var iwk_date = {
		//根据yyyy-MM-dd格式化日期为date对象
		formatStr:function(str){
			str = $.trim(str);
			strAll = str.split(" ");
			var strs = strAll[0].split("-");
			var strs2;
			if(strAll[1]){
				strs2 = strAll[1].split(":");
				return new Date(strs[0],strs[1]-1,strs[2],strs2[0],strs2[1]);
			}
			return new Date(strs[0],strs[1]-1,strs[2]);
		},
		//根据yyyy-MM-dd hh:mm格式化日期为date对象
		formatFullTime:function(str){
			var _date = str.split(" ");
			var _days = _date[0].split("-");
			var _time = _date[1].split(":");
			return new Date(_days[0],_days[1]-1,_days[2],_time[0],_time[1]);
		},
		formatDate:function(_date){
			return _date.getFullYear()+"-"+((_date.getMonth()+1)<10?'0'+(_date.getMonth()+1):(_date.getMonth()+1))+"-"+(_date.getDate()<10?'0'+_date.getDate():_date.getDate());
		},
		formatFullDate:function(_date){
			return _date.getFullYear()+"-"+(_date.getMonth()+1)+"-"+_date.getDate()+" "+_date.getHours()+":"+(_date.getMinutes()<10?'0'+_date.getMinutes():_date.getMinutes());
		},
		formatTime:function(_date){
			return _date.getHours()+":"+(_date.getMinutes()<10?'0'+_date.getMinutes():_date.getMinutes());
		},
		//根据date对象拿到本周一
		getWeekStartDay:function(date){
			return new Date(date.getFullYear(),date.getMonth(),date.getDate()-date.getDay()+1);
		},
		//根据date对象拿到本周日
		getWeekEndDay:function(date){
			return new Date(date.getFullYear(),date.getMonth(),date.getDate()-date.getDay()+7);
		},
		getMonthStartDay:function(date){
			return new Date(date.getFullYear(),date.getMonth(),1);
		},
		getMonthEndDay:function(date){
			return new Date(date.getFullYear(),date.getMonth()+1,0);
		}
};

var iwk_top = {
	search : function() {
		var _s = $.trim($("div.iwk_top_head .search_input input").val());
		var _t = $("div.iwk_top_head .search_select .search_select_ttl");

		if ($.trim(_s) === '') {
			zebra_auto('请输入关键词', 1000);
			return;
		}
		window.location.href = '' + "inside/search/tab:"
				+ _t.attr("data") + "/s:" + encodeURIComponent(_s);
	},
	crkey : function(e) {
		var code = '';
		if (e.keyCode) {
			code = e.keyCode;
		} else if (e.which) {
			code = e.which;
		}
		if (code == 13) {
			var _s = $("#head_search_ipt").val();
			var _t = $("#ihcs_filter_ttl");
			window.location.href = '' + "inside/search/tab:"
					+ _t.attr("data") + "/s:" + _s;
		}
	}
};
// 帖子JS对象
var iwk_post = {
	morer_start_from : 10,
	morer_pulling_down : 0,
	user_dropdown_timeout : 0,

	del_reply : function(post_id, comment_id, callback_after) {
		zebra_confirm(iwk_lng.postcomment_delete_confirm_msg, function() {
			var _data = {
				"postid" : post_id,
				"commentid" : comment_id
			};
			$.post('' + 'ajax/comment_del/r:'
					+ Math.round(Math.random() * 1000), _data, function() {
				if (callback_after)
					callback_after();
			});
		});
	},
	edit : function(postid, callback_after) {
		var _data = {
			"postid" : postid
		};
		$.post('' + 'ajax/postform_loadpost/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			if (callback_after)
				callback_after(res);
		}, 'json');
	},
	del : function(postid, callback_after, callback_onclose) {
		zebra_confirm(iwk_lng.post_delete_confirm_msg, function() {
			var _data = {
				"postid" : postid
			};
			$.post('' + 'ajax/post_del/r:'
					+ Math.round(Math.random() * 1000), _data, function() {
				if (callback_after)
					callback_after();
			});
		}, null, callback_onclose);
	},

	// 删除单条发贴按钮(自己的发贴)
	post_delete : function(_this, post_id) {
		iwk_post.del(post_id, function() {
			$("#sp_" + post_id).slideUp('slow', function() {
				$(_this).remove();
			});
		});
	},

	post_delete_v : function(post_id) {
		var _is_deleted = false;

		iwk_post.del(post_id, function() {
			$("#view_wrap").empty().html(
					'<div style="padding:10px 0;"><a href="' + ''
							+ '">返回首页</a></div>');
			_is_deleted = true;
		}, function() {
			if (_is_deleted) {
				zebra_alert("删除成功!");
			}
		});
	},

	init_comment_cfg : function() {
		iwk_cfg_comment.temp_id = iwk_common.get_new_guid();
		iwk_cfg_comment.sending = 0;
		iwk_cfg_comment.attach_sending = 0;
	},

	// 回复按钮 - 展开回帖栏及回复
	post_reply : function(_this, post_id) {
		var _parent = $("#sp_" + post_id);
		if (iwk_cfg.is_ie) {
			_parent.find(".comments").toggle();
		} else {
			_parent.find(".comments").slideToggle();
		}
		iwk_post.postcomments_mark(post_id);
	},

	// 取消回复标记
	postcomments_mark : function(post_id) {
		$.post('' + 'ajax/postcomments_mark/r:'
				+ Math.round(Math.random() * 1000), "postid="
				+ encodeURIComponent(post_id), function() {
			if ($('#post_newcomments_' + post_id).length > 0) {
				$('#post_newcomments_' + post_id).hide();
			}
		});
	},

	remove_comment_attach_by_code : function(instance_id, file_id) {
		$('#' + instance_id).uploadify('cancel', file_id);
		iwk_post.uploadifier_size_limit(instance_id);

		var _url = '' + 'ajax/postcomment_attach';
		var _args = {
			"post_temp_id" : iwk_cfg_comment.temp_id,
			"flag" : file_id,
			"remove" : true
		};
		$.post(_url, _args, function(res) {
			if (res == file_id) {

			}
		});
	},
	
	uploadifier_size_limit : function(_upload_id){
		var _queue_id = $('#'+ _upload_id).uploadify('settings', 'queueID');
		
		var _items = $('#'+_queue_id).find('.uploadify-queue-item');
		if(_items.length >= 5){
			$('#'+ _upload_id).uploadify('disable', true);
		}else{
			$('#'+ _upload_id).uploadify('disable', false);
		}
	},

	remove_comment_attach : function(instance_id, file_id) {
		zebra_confirm("确认删除此附件吗?", function() {
			iwk_post.remove_comment_attach_by_code(instance_id, file_id);
		});
	},

	comment_uploadify : function(_ipt, _queue_id) {
		_ipt
				.uploadify({
					'checkExisting' : false,
					'swf' : ''
							+ 'themes/art/js/uploadify/uploadify.swf',
					'uploader' : '' + 'ajax/postform_attachupl',
					'uploadLimit' : 0,
					'queueSizeLimit' : 10,
					'width' : '40',
					'height' : '25',
					'buttonClass' : 'iwk_attachment_btn',
					'buttonText' : '',
					'fileObjName' : 'file',
					'fileSizeLimit' : '30MB',
					'queueID' : _queue_id,
					'removeCompleted' : false,
					'itemTemplate' : '<div id="${fileID}" class="uploadify-queue-item" instanceid="${instanceID}" fileid="${fileID}">\
									<div class="cancel">\
										<a href="javascript:iwk_post.remove_comment_attach(\'${instanceID}\', \'${fileID}\')">删除</a>\
									</div>\
									<span class="fileName">${fileName} (${fileSize})</span><span class="data"></span>\
									<div class="uploadify-progress">\
										<div class="uploadify-progress-bar"></div>\
									</div>\
								</div>',
					'method' : 'post',
					'onFallback' : function() {
						// alert('Flash was not detected.');
					},
					'onUploadStart' : function(file) {
						iwk_cfg_comment.attach_sending = 1;
						$('#' + this.settings.id).uploadify('settings',
								'formData', {
									'flag' : file.id,
									'session_id' : iwk_cfg.sid
								});
					},
					'onUploadSuccess' : function(file, data, response) {
						var _url = '' + 'ajax/postcomment_attach';
						$.post(_url, {
							'post_temp_id' : iwk_cfg_comment.temp_id,
							'flag' : file.id
						}, function(res) {
							iwk_cfg_comment.attach_sending = 0;
						});
					},
					'onSelect' : function(file) {
						var _upload_id = this.settings.id;
						uploadifier_on_select(_upload_id, file.id);
					}
				});
	},

	// 回复帖子按钮 - 回复新信息
	single_post_comment_fake : function(_this, _queue_id) {
		iwk_post.init_comment_cfg();
		$(_this).hide().next(".real").show().find("textarea").focus();

		var _cfu = $(_this).parent().find('.comment_attach_btn');
		if (_cfu.length) {
			iwk_post.comment_uploadify(_cfu, _queue_id);
		}
	},

	// 取消回帖按钮 - 收起回帖栏
	single_post_comment_cancel : function(_this) {
		var cmt_head = $(_this).closest(".cmt_head");
		cmt_head.find(".upl_attaches").find('.uploadify-queue-item')
				.each(
						function() {
							var _instanceid = $(this).attr('instanceid');
							var _fileid = $(this).attr('fileid');
							iwk_post.remove_comment_attach_by_code(_instanceid,
									_fileid);
							$(this).remove();
						});
		cmt_head.find(".real").hide();
		cmt_head.find(".fake").show();
	},

	comment_send : function(_this, callback) {
		var _pid = $(_this).attr("data");
		var _parent = $(_this).attr("parent");
		var _textarea = $(_this).closest(".file_upl_wrap").find('textarea');
		var _msg = $.trim(_textarea.val());
		var _data = {
			parent : _parent,
			postid : _pid,
			message : _msg,
			post_temp_id : iwk_cfg_comment.temp_id
		};

		if (_msg === "") {
			zebra_alert(iwk_lng.post_empty_comment);
			return;
		}
		if (iwk_cfg_comment.attach_sending) {
			zebra_alert(iwk_lng.attach_is_sending_msg);
			return;
		}
		if (iwk_cfg_comment.sending) {
			zebra_alert(iwk_lng.is_sending_msg);
			return;
		}

		_textarea.attr("disabled", "disabled");
		$(_this).attr("disabled", "disabled");

		iwk_cfg_comment.sending = 1;
		$.post('' + 'ajax/postcomment/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			if (res.status.toLowerCase() == "ok") {
				iwk_post.init_comment_cfg();
				callback();
			} else {
				zebra_alert(res.message);
				iwk_cfg_comment.sending = 0;
				_textarea.removeAttr("disabled");
			}
		}, 'json');
	},

	// 发送回帖按钮 - 发送回帖信息
	single_post_comment_send : function(_this) {
		iwk_post.comment_send(_this, function() {
			var _pid = $(_this).attr("data");
			iwk_post.synchronize_single(_pid);
		});
	},

	single_post_comment_send_v : function(_this) {
		iwk_post.comment_send(_this, function() {
			view_refresh_callback('回复成功!');
		});
	},

	// 再次回复帖子按钮 - 回复新信息
	single_post_recomment : function(_this, _queue_id) {
		iwk_post.init_comment_cfg();
		var _item = $(_this).closest(".cmt_item");
		_item.find(".re_reply").show().find("textarea").focus();

		var _rcfu = _item.find('.recomment_attach_btn');
		if (_rcfu.length) {
			iwk_post.comment_uploadify(_rcfu, _queue_id);
		}
	},

	// 取消在回复回帖按钮 - 收起回帖栏
	single_post_recomment_cancel : function(_this) {
		var _item = $(_this).closest(".cmt_item");
		_item.find(".recomment_upl_attaches").find('.uploadify-queue-item')
				.each(
						function() {
							var _instanceid = $(this).attr('instanceid');
							var _fileid = $(this).attr('fileid');
							iwk_post.remove_comment_attach_by_code(_instanceid,
									_fileid);
							$(this).remove();
						});
		_item.find(".re_reply").hide();
	},

	// 帖子无刷新同步
	synchronize : function(callback, cancelProgress) {
		var _url = window.location.href.toString();
		if (iwk_cfg.is_ie) {
			_url = encodeURI(_url);
		}

		if (!_url) {
			return;
		}
		if (_url.substr(0, ''.length) == '') {
			_url = _url.substr(''.length);
			if (!_url) {
				_url = 'inside/dashboard';
			}
			_url = '' + _url + "/from:ajax/r:"
					+ Math.round(Math.random() * 1000);
		} else {
			if (iwk_common.get_query_str("link") != null) {
				_url = _url + "/add:postform";
			}
			_url = _url.replace(/^http(s)?\:\/\//, "");
			_url = _url.substr(_url.indexOf("/"));
			_url = '' + _url + "/from:ajax/r:"
					+ Math.round(Math.random() * 1000);
		}

		var _lastpostdate = 0, posts = $('.iwk_posts');

		if (posts.length == 0) {
			posts = $('#view_wrap');
		}

		posts.children().each(function() {
			var tmpdate = parseInt($(this).attr('postdate'), 10);
			if (tmpdate > _lastpostdate) {
				_lastpostdate = tmpdate;
			}
		});

		$
				.post(
						_url,
						{
							"lastpostdate" : _lastpostdate
						},
						function(txt) {
							txt = jQuery.trim(txt);
							if (txt.substr(0, 3) != "OK:") {
								return;
							}
							/*
							 * var get_last_post_id =
							 * txt.match(/LAST_POST_ID\:([0-9]+)\:/g); //edit
							 * match here if( ! get_last_post_id ) { return; }
							 * get_last_post_id =
							 * get_last_post_id.toString().match(/([0-9]+)/g);
							 * //edit get_last_post_id =
							 * parseInt(get_last_post_id, 10); last_post_id =
							 * get_last_post_id;
							 */
							txt = txt
									.replace(
											/^OK\:([0-9]+)\:NUM_POSTS\:([0-9]+)\:LAST_POST_ID\:([0-9]+)\:/,
											"");
							txt = $(txt);

							posts.html(txt);

							posts.children().each(function() {
								if ($(this).css('display') == 'none') {
									$(this).slideToggle('slow');
								}
							});
							// add by Erich Lee
							// resolve private message bugs:
							// 每次刷新有2次请求
							// 上传图片未完成自动隐藏进度条
							if (callback && $.isFunction(callback)) {
								callback.call();
							}
							if (cancelProgress == 'undefined'
									|| cancelProgress == true) {
								fancylay.unblock();
							}
						});
	},

	// 帖子无刷新单条同步
	synchronize_single : function(post_id) {
		var comments_open = 0;
		var _comments_div = $("#sp_" + post_id).find(".comments");
		if (_comments_div.css("display") == "block") {
			comments_open = 1;
		}
		var _data = {
			"post_id" : post_id,
			"display_comments" : comments_open,
			"page_name" : iwk_cfg.page_name
		};
		$.post('' + 'ajax/single_post_synchronize/r:'
				+ Math.round(Math.random() * 1000), _data, function(txt) {
			if (txt.substr(0, 3) != "OK:") {
				return;
			}
			txt = txt.replace(/^OK\:/, "");
			txt = $(jQuery.trim(txt));

			var layer = $("#sp_" + post_id);
			layer.replaceWith(txt).show();
			if (comments_open == 1) {
				layer.find(".comments").show();
			}
			/*
			 * $("#sp_"+post_id).slideUp('slow', function(){
			 * $(this).replaceWith(txt); $("#sp_" + post_id).slideDown(); if
			 * (comments_open ==1){ $("#sp_" +
			 * post_id).find(".comments").slideDown(); } });
			 */
		});
	},

	// 显示更多帖子按钮
	morer_wrap : function(_this) {
		// if(iwk_post.morer_pulling_down){return;}
		iwk_post.morer_pulling_down = 1;
		// $(_this).find("a").removeClass("more_arrow").addClass("loading_spinner");
		$(_this).find("a").find(".spinner").show();
		iwk_post.loading_more("iwk_posts", iwk_post.morer_start_from);
	},

	// 显示更多帖子
	loading_more : function(_div, res_num) {

		res_num = parseInt(res_num, 10);
		var url = window.location.href.toString();
		if (!url) {
			return;
		}
		var _url = document.URL;
		if (url.substr(0, ''.length) == '') {
			url = url.substr(''.length);
			if (url.indexOf("#") != -1) {
				url = url.substr(0, url.indexOf("#"));
			}
			if (!url) {
				url = 'inside/dashboard';
			}
			// url =
			// ''+url+"/from:ajax"+"/start_from:"+(res_num)+"/r:"+Math.round(Math.random()*1000);
			url = '' + url + "/from:ajax" + "/start_from:"
					+ (res_num) + "/r:" + Math.round(Math.random() * 1000);
		} else {
			url = url.replace(/^http(s)?\:\/\//, "");
			url = url.substr(url.indexOf("/"));
			if (url.indexOf("#") != -1) {
				url = url.substr(0, url.indexOf("#"));
			}
			// url =
			// ''+url+"/m:ajax"+"/r:"+Math.round(Math.random()*1000);
			url = _url + "/from:ajax" + "/r:"
					+ Math.round(Math.random() * 1000);
		}
		$
				.get(
						url,
						function(data) {
							var txt = jQuery.trim(data);

							var num_new_posts = txt
									.match(/NUM_POSTS\:([0-9]+)\:/g);
							if (!num_new_posts) {
								return;
							}
							num_new_posts = num_new_posts.toString().match(
									/([0-9]+)/);
							num_new_posts = parseInt(num_new_posts, 10);

							var start_from = txt.match(/^OK\:([0-9]+)\:/g);
							if (!start_from) {
								return;
							}
							start_from = start_from.toString()
									.match(/([0-9]+)/);
							start_from = parseInt(start_from, 10);
							if (start_from < 0) {
								return;
							}
							txt = txt
									.replace(
											/^OK\:([0-9]+)\:NUM_POSTS\:([0-9]+)\:LAST_POST_ID\:([0-9]+)\:/,
											"");
							txt = $(txt);

							$('.' + _div).append($(txt));

							if (iwk_cfg.post_partial_view) {
								txt.find(".text_collapse").each(
										function(i, dom) {
											iwk_main.partial_view(dom);
										});
							}

							iwk_post.morer_start_from = start_from;
							iwk_post.morer_pulling_down = 0;
							$(".iwk_more_loader").find("a").find(".spinner")
									.hide();
							if (num_new_posts < 10) {
								$(".iwk_more_loader").hide();
							}

							if (num_new_posts < 10) {
								$("#morer_wrap_arrow").remove();
								return;
							}
						});
	},

	// 显示更多帖子按钮(表格布局)
	morer_wrap_table : function(_this) {
		if (iwk_post.morer_pulling_down) {
			return;
		}
		iwk_post.morer_pulling_down = 1;
		// $(_this).find("a").removeClass("more_arrow").addClass("loading_spinner");
		$(_this).find("a").removeClass("more_arrow");
		iwk_post.loading_more_table("iwk_posts", iwk_post.morer_start_from);
	},

	// 显示更多帖子
	loading_more_table : function(_div, res_num) {

		res_num = parseInt(res_num, 10);
		var url = window.location.href.toString();
		if (!url) {
			return;
		}

		if (url.substr(0, ''.length) == '') {
			url = url.substr(''.length);
			if (url.indexOf("#") != -1) {
				url = url.substr(0, url.indexOf("#"));
			}
			if (!url) {
				url = 'inside/dashboard';
			}
			url = '' + url + "/from:ajax" + "/start_from:"
					+ (res_num) + "/r:" + Math.round(Math.random() * 1000);
		} else {
			url = url.replace(/^http(s)?\:\/\//, "");
			url = url.substr(url.indexOf("/"));
			if (url.indexOf("#") != -1) {
				url = url.substr(0, url.indexOf("#"));
			}
			url = '' + url + "/from:ajax" + "/r:"
					+ Math.round(Math.random() * 1000);
		}

		$
				.get(
						url,
						function(data) {
							var txt = jQuery.trim(data);

							var num_new_posts = txt
									.match(/NUM_POSTS\:([0-9]+)\:/g);
							if (!num_new_posts) {
								return;
							}
							num_new_posts = num_new_posts.toString().match(
									/([0-9]+)/);
							num_new_posts = parseInt(num_new_posts, 10);

							var start_from = txt.match(/^OK\:([0-9]+)\:/g);
							if (!start_from) {
								return;
							}
							start_from = start_from.toString()
									.match(/([0-9]+)/);
							start_from = parseInt(start_from, 10);
							if (start_from < 0) {
								return;
							}
							txt = txt
									.replace(
											/^OK\:([0-9]+)\:NUM_POSTS\:([0-9]+)\:LAST_POST_ID\:([0-9]+)\:/,
											"");
							txt = $(txt);

							$('.' + _div).find("table").find("tbody").append(
									$(txt));

							if (iwk_cfg.post_partial_view) {
								txt.find(".text_collapse").each(
										function(i, dom) {
											iwk_main.partial_view(dom);
										});
							}

							iwk_post.morer_start_from = start_from;
							iwk_post.morer_pulling_down = 0;
							$(".more_loader").find("a").removeClass(
									"loading_spinner").addClass("more_arrow");

							if (num_new_posts < 10) {
								$("#morer_wrap_arrow").remove();
								return;
							}
						});
	},

	// 删除单条回复按钮(自己回的帖)
	post_comment_delete : function(_this) {
		var _pid = $(_this).attr("data_p");
		var _pcid = $(_this).attr("data_pc");
		var _post = $("#sp_" + _pid);
		iwk_post.del_reply(_pid, _pcid, function() {
			var count = _post.find(".iwk_single_comment").length
					+ _post.find(".iwk_single_recomment").length
					- $("#spc_" + _pcid).find(".iwk_single_recomment").length
					- 1;
			if (count == 0) {
				_post.find("div.ispc_func_items").find("div.reply").html(
						"<i></i>回复");
				_post.find("div.comments").slideUp("slow", function() {
					$("#spc_" + _pcid).remove();
				});
			} else {
				_post.find("div.ispc_func_items").find("div.reply").html(
						"<i></i>回复(" + count+")");
				$("#spc_" + _pcid).slideUp("slow", function() {
					$(this).remove();
				});
			}
		});
	},

	// 删除单条回复的回复按钮(自己回的帖)
	post_recomment_delete : function(_this) {
		var _pid = $(_this).attr("data_p");
		var _pcid = $(_this).attr("data_pc");
		var _post = $("#sp_" + _pid);
		iwk_post.del_reply(_pid, _pcid, function() {
			var count = _post.find(".iwk_single_comment").length
					+ _post.find(".iwk_single_recomment").length - 1;
			_post.find("div.down").find("div.reply").html("回复(" + count + ")");
			$("#spc_" + _pcid).slideUp("slow", function() {
				$(this).remove();
			});
		});
	},

	// 查看原始图片附件
	view_img_attach : function(_this,_pre,_next) {
		var clientWidth = $(window).width(), clientHeight = $(window).height(), limitW = clientWidth - 100, limitH = clientHeight - 200;
		$.fancybox({
			'type' : 'ajax',
			'href' : $(_this).attr('data'),
			'helpers' : {
				overlay : {
					opacity : 0.2
				}
			},
			'beforeShow' : function() {
				var img = $('.flybox_attach_img img'), theImg = $('<img/>')
						.get(0);

				theImg.onload = function() {
					var w = this.width, h = this.height, isChange = false;
					
					while (w > limitW || h > limitH) {
						w *= 0.75;
						h *= 0.75;
						isChange = true;
					}

					if (isChange) {
						img.css({
							height : h + 'px',
							width : w + 'px'
						})// .parents('.fancybox-inner').css('width', w+'px');
					}
				};
				theImg.src = img.attr('src');
				if(_pre || _next){
					iwk_post.pic_now=$(_this);
					var img_wrap = $('.flybox_attach_img');
//					img_wrap.mousemove(function(e){
//						if(e.offsetX<img_wrap.width()*0.4 && _pre && $(".fancy_left").length == 0){
//							$('.flybox_attach_img').append('<a title="Next" class="fancybox_link fancy_left" onclick="iwk_post.pre()" href="javascript:;"><span></span></a>');
//						}
//						if(e.offsetX>img_wrap.width()*0.6 && _next && $(".fancy_right").length == 0){
//							$('.flybox_attach_img').append('<a title="Next" class="fancybox_link fancy_right" onclick="iwk_post.next()" href="javascript:;"><span></span></a>');
//						}
//					});
					
					if(_pre){
						$('.flybox_attach_img').append('<a title="上一张" class="fancybox_link fancy_left" onclick="iwk_post.pre()" href="javascript:;"><span></span></a>');
					}
					if(_next){
						$('.flybox_attach_img').append('<a title="下一张" class="fancybox_link fancy_right" onclick="iwk_post.next()" href="javascript:;"><span></span></a>');
					}
				}
			}
		});
	},
	pic_now:'',
	pre : function(_this){
		iwk_post.pic_now.prev().click();
	},
	next : function(_this){
		iwk_post.pic_now.next().click();
	},
	_timeout : '',
	//在线预览文件（office文档和pdf）
	view_file_attach : function(_this,_id,_type) {
		var _url = '';
		if(!_this){
			_url = ''+"inside/"+_type+"/id:"+_id+"/r:"+Math.round(Math.random() * 1000);
		}else{
			_url = $(_this).attr('data')+"/r:"+Math.round(Math.random() * 1000)
		}
		var clientWidth = 0;
		$.fancybox({
			width: 750,
			height: 500,
			'type' : 'ajax',
			'href' : _url,
			'helpers' : {
				overlay : {
					opacity : 0.2
				}
			},
			'beforeShow' : function() {
				
			},
			'afterClose' : function(){
				clearTimeout(iwk_post._timeout);
				iwk_post._timeout= '';
			}
		});
	},

	toggle : function(_this) {
		$txt_clp = $(_this).prev('.text_collapse');
		if ($txt_clp) {
			cur_height = $txt_clp.height(), auto_height = $txt_clp.css(
					'height', 'auto').height();

			if ($(_this).hasClass('fold')
					&& auto_height > iwk_main.partial_view_height) {
				$txt_clp.animate({
					height : iwk_main.partial_view_height + 'px'
				}, 300);
			} else {
				$txt_clp.height(cur_height).animate({
					height : auto_height
				}, 300);
			}
		}
		$(_this).toggleClass('fold');
		$(_this).closest('.iwk_single_post').find('.toggle_item').slideToggle();
	},

	// 催办按钮
	urge : function(_postid) {
		$.fancybox({
			'modal' : false,
			'scrolling' : 'no',
			'href' : '#foot_post_urge_picker',
			'helpers' : {
				overlay : {
					opacity : 0.2
				}
			},
			'beforeLoad' : function() {
				$("#iwk_urge_textarea").val('');
				$("#iwk_urge_post_id").val(_postid);
			}
		});
	},

	post_urge : function(_postid) {
		iwk_post.urge(_postid);
	},
	// 转发确定
	post_urge_ok : function() {
		$.fancybox.close();

		var _data = {};
		_data.postid = $("#iwk_urge_post_id").val();
		_data.text = $("#iwk_urge_textarea").val();
		_data.is_sms_urge = $('#iwk_urge_is_sms').is(":checked") ? 1 : 0;
		// 阻塞
		fancylay.block();
		$.post('' + 'ajax/post_update/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			if (res.status.toLowerCase() == 'ok') {
				if (iwk_cfg.page_name == 'view') {
					var _pid = 'public_' + _data.postid;
					iwk_post.synchronize_single(_pid);
				} else {
					iwk_post.synchronize();
				}
			}
			fancylay.unblock();
			zebra_alert(res.message);
		}, 'json');
	},

	// 显示提醒
	alarm_over : function(_this) {
		$(_this).find(".reminder_tip_wrap").show();
	},

	// 隐藏提醒
	alarm_out : function(_this) {
		$(_this).find(".reminder_tip_wrap").hide();
	},

	over_alarm : function(_this) {
		$(_this).find(".reminder_tip_wrap").toggle();
	},
	// 更新帖子状态
	post_proc : function(posttmpid, type, _pric_val) {
		var _data = {
			"postid" : posttmpid
		};
		_data.exec_type = type;
		_data.val = _pric_val;
		// zebra_confirm(iwk_lng.post_exec_comfirm, function(){
		$.post('' + 'ajax/post_update/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			if (res.status.toLowerCase() == 'ok') {
				zebra_auto('操作成功', 1000);
				iwk_post.morer_start_from = 10;
				iwk_post.synchronize();
			} else {
				zebra_alert(res.message);
			}
		}, 'json');
		// }, null);
	}
};

// 报销JS对象
var iwk_afr = {
	sendding : 0,

	edit : function(postid, callback_after) {
		var _data = {
			"postid" : postid
		};
		$.post('' + 'apps/afr/ajax/formloadtask/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			if (callback_after)
				callback_after(res);
		}, 'json');
	},
	del : function(postid, callback_after, callback_onclose) {
		zebra_confirm(iwk_lng.afr_delete_confirm_msg, function() {
			var _data = {
				"postid" : postid
			};
			$.post('' + 'apps/afr/ajax/delete/r:'
					+ Math.round(Math.random() * 1000), _data, function() {
				if (callback_after)
					callback_after();
			});
		}, null, callback_onclose);
	},
	// 删除单条发贴按钮(自己的发贴)
	afr_delete : function(_this, post_id) {
		iwk_afr.del(post_id, function() {
			$("#sp_" + post_id).slideUp('slow', function() {
				$(_this).remove();
			});
		});
	},

	afr_delete_v : function(post_id) {
		var _is_deleted = false;

		iwk_afr.del(post_id, function() {
			$("#view_wrap").empty().html(
					'<div style="padding:10px 0;"><a href="' + ''
							+ '">返回首页</a></div>');
			_is_deleted = true;
		}, function() {
			if (_is_deleted) {
				zebra_alert("删除成功!");
			}
		});
	},

	// 报销审核按钮
	audit : function(_this, _post_id, _afrid, _state, callback) {
		var _data = {
			"postid" : _post_id
		};
		_data.state = _state;
		_data.afrid = _afrid;
		_data.type = "state";

		if (iwk_afr.sending) {
			return;
		}

		iwk_afr.sending = 1;
		$.post('' + 'apps/afr/ajax/update/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			if (!jQuery.isEmptyObject(res) && res.status == 'OK') {
				callback();
			} else {
				zebra_alert(res.message);
			}
			iwk_afr.sending = 0;
		}, 'json');
	},

	afr_audit : function(_this, _post_id, _afrid, _state) {
		var __this = $(this);
		if (__this.attr('handling') != 'true') {
			__this.attr('handling', 'true');
			iwk_afr.audit(_this, _post_id, _afrid, _state, function() {
				if (iwk_cfg.page_name == 'view') {
					iwk_post.synchronize_single(_post_id);
				} else {
					iwk_post.synchronize();
				}
				__this.attr('handling', 'false');
			});
		}
	},

	afr_audit_v : function(_this, _post_id, _afrid, _state) {
		iwk_afr.audit(_this, _post_id, _afrid, _state, function() {
			view_refresh_callback('审核成功!');
		});
	},

	// 报销打回按钮
	callback : function(_this, _post_id, _afrid, callback) {
		// 阻塞
		fancylay.block();
		var _data = {
			"postid" : _post_id,
			"afrid" : _afrid,
			"type" : "back"
		};
		$.post('' + 'apps/afr/ajax/update/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			iwk_cfg_postform.sending = 0;
			$.fancybox.hideLoading();
			if (res.status == 'OK') {
				// 撤销阻塞
				fancylay.unblock();
				callback();
			} else {
				fancylay.unblock();
				zebra_alert(res.message);
			}
		}, 'json');
	},

	afr_callback : function(_this, _post_id, _afrid) {
		iwk_afr.callback(_this, _post_id, _afrid, function() {
			if (iwk_cfg.page_name == 'view') {
				iwk_post.synchronize_single(_post_id);
			} else {
				iwk_post.synchronize();
			}
		});
	},

	afr_callback_v : function(_this, _post_id, _afrid) {
		iwk_afr.callback(_this, _post_id, _afrid, function() {
			view_refresh_callback('打回成功!');
		});
	},

	// 报销转发按钮
	transfer : function(_postid, _afrid) {

		$.fancybox({
			'modal' : false,
			'scrolling' : 'no',
			'href' : '#foot_common_user_picker',
			'helpers' : {
				overlay : {
					opacity : 0.2
				}
			},
			'beforeLoad' : function() {
				$("#fcup_multipicker").userpicker("clear");
				$("#foot_common_user_picker .btn").hide();
				$("#fcup_btn_afr").show();
				$("#fcup_textarea").val('').hide();
				$("#fcup_ipt_a, #fcup_ipt_b").val('');
				$("#fcup_ipt_a").val(_postid);
				$("#fcup_ipt_b").val(_afrid);
			},
			'afterShow' : function() {

			}
		});
	},

	afr_transfer : function(_postid, _afrid) {
		iwk_afr.transfer(_postid, _afrid);
	},

	afr_transfer_v : function(_postid, _afrid) {
		iwk_afr.transfer(_postid, _afrid, 'view');
	},
	afr_print : function(_postid) {
		window.open('' + 'apps/afr/print/post:' + _postid,
				"_blank");
		return false;
	},
	afr_transfer_ok : function() {
		var _r = $("#fcup_multipicker").userpicker("getData");
		if (_r.user && _r.user[0]) {
			$.fancybox.close();
			var _data = {
				"userid" : _r.user[0],
				"type" : "intransit"
			};

			_data.postid = $("#fcup_ipt_a").val();
			_data.afrid = $("#fcup_ipt_b").val();
			var _display = $("#fcup_textarea").css("display");
			if (_display == 'none') {
				_data.reason = '';
			} else {
				_data.reason = $("#fcup_textarea").val();
			}

			$.post('' + 'apps/afr/ajax/update/r:'
					+ Math.round(Math.random() * 1000), _data, function(res) {
				if (res.status == 'OK') {
					if (iwk_cfg.page_name == 'view') {
						iwk_post.synchronize_single(_data.postid);
					} else {
						iwk_post.synchronize();
					}
				}
				zebra_alert(res.message);
			}, 'json');
		} else {
			zebra_alert("请选择用户!");
		}
	},

	afr_form_show : function() {

		$.fancybox({
			'modal' : true,
			'scrolling' : 'visible',
			'href' : '#postform_body_afr',
			'helpers' : {
				overlay : {
					opacity : 0.2
				}
			},
			'beforeLoad' : function() {

			}
		});

	},
	send_p_afr : function() {
		var _msg = $.trim($("#pf_afr_textarea").val());
		var _amount = $.trim($("#amount").val());
		var _anamount = _amount * 100;
		// 判断是否金额的正则表达式，暂时不能判断0.00，如果找到好的，请替换
		var reg = /(^[1-9]\d*(\.\d{1,2})?$)|(^[0]?\.\d{1,2}$)/;
		var _data = {
			"post_temp_id" : iwk_cfg_postform.temp_id,
			"message" : _msg,
			"amount" : _amount
		};

		if (_msg == "") {
			zebra_alert(iwk_lng.afr_empty_message);
			return;
		}
		if (!reg.test(_anamount)) {
			zebra_alert(iwk_lng.afr_error_amount);
			return;
		}

		if (iwk_cfg_postform.attach_sending) {
			zebra_alert(iwk_lng.attach_is_sending_msg);
			return;
		}
		if (iwk_cfg_postform.sending) {
			zebra_alert(iwk_lng.is_sending_msg);
			return;
		}

		var _feetype = $("#pf_fee_type").val();

		if (_feetype != "") {
			_data.feetype = _feetype;
		} else {
			zebra_alert(iwk_lng.afr_empty_feetype);
			return;
		}
		// 流程
		if (iwk_cfg_postform.flow_afr_level == 0) {
			zebra_alert(iwk_lng.afr_empty_audit);
			return;
		}

		if (iwk_cfg_postform.post_id != 0) {
			var id = iwk_cfg_postform.post_id.split("_");
			if (id != null && $(id).size() > 1 && id[1] > 0) {
				_data.editpost = iwk_cfg_postform.post_id;
				_data.removed_attaches = iwk_cfg_postform.removed_attaches
						.join(",");
			}
		}

		var _project = $("#pf_afr_project").pulldown("getVal");
		if (_project && _project.res) {
			_data.project_id = _project.res;
		}

		var _customer = $('#pf_afr_customer').pulldown('getVal');
		if (_customer && _customer.res) {
			_data.customer_id = _customer.res;
		}

		var _startdate = $("#postform_afr_begin").val();
		if (_startdate != "") {
			_data.startdate = _startdate;
		}

		var _enddate = $("#postform_afr_end").val();
		if (_enddate != "") {
			_data.enddate = _enddate;
		}
		if (_startdate > _enddate) {
			zebra_alert(iwk_lng.afr_date_over);
			return;
		}

		var _feetype = $("#pf_fee_type").val();
		if (parseInt(_feetype) > 0) {
			_data.feetype = _feetype;
		} else {
			zebra_alert(iwk_lng.afr_empty_feetype);
			return;
		}

		iwk_cfg_postform.sending = 1;
		$.post('' + 'apps/afr/ajax/formsubmit/ajaxtp:xml/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			var _st = res.status;
			if (_st == "ok") {
				if (_data.editpost) {
					$("#pf_cancel_edit").click();
				}
				iwk_postform.init_postform_cfg();
				iwk_postform.show_type(true);
				iwk_afr.p_afr_show();
				iwk_post.synchronize();
			} else {
				zebra_alert(res.message);
				iwk_cfg_postform.sending = 0;
			}
			$.fancybox.close();
		}, 'json');

	},
	// 显示报销
	p_afr_show : function() {
		// 修改为自己需要的类型
		iwk_cfg_postform.to.type = iwk_cfg_postform.const_type.afr;
		if (iwk_cfg_postform.to.can_choose_scope) {
			iwk_cfg_postform.to.scope = iwk_cfg_postform.const_scope.all;
			iwk_cfg_postform.to.id = "";
		}

		// 各自类型的iwk_postform_body里面的内容
		$("#pf_afr_textarea").val("");

		$("#pf_fee_type").val("");
		$("#fee_type_down").find(".pull_down_ttl").html(
				iwk_lng.postform_init_option);

		$("#amount").val("0.00");

		var _time = new Date();
		_time.setHours(_time.getHours() + 1);
		$("#postform_afr_begin").val(_time.format("yyyy-MM-dd"));
		$("#postform_afr_end").val(_time.format("yyyy-MM-dd"));

		if (!$("#pf_afr_customer").pulldown("isLock")) {
			$('#pf_afr_customer').pulldown('setVal', {
				ttl : "关联客户",
				res : 0
			});
		}
		// 公用的部分，包括头部和附件两个地方
		iwk_postform.show_group(false);
		iwk_postform.show_customer(false);
		$(".iwk_postform_attachs").empty();
		$("#postform_body_afr").show();
	}
};

// 请假JS对象
var iwk_leave = {
	sending : 0,

	edit : function(postid, callback_after) {
		var _data = {
			"postid" : postid
		};
		$.post('' + 'apps/flow/ajax/leave_formload/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			if (callback_after)
				callback_after(res);
		}, 'json');
	},
	del : function(postid, callback_after, callback_onclose) {
		zebra_confirm(iwk_lng.leave_delete_confirm_msg, function() {
			var _data = {
				"postid" : postid
			};
			$.post('' + 'apps/flow/ajax/delete/r:'
					+ Math.round(Math.random() * 1000), _data, function(res) {
				if (callback_after)
					callback_after();
			});
		}, null, callback_onclose);
	},
	// 删除单条发贴按钮(自己的发贴)
	leave_delete : function(_this, post_id) {
		iwk_leave.del(post_id, function() {
			$("#sp_" + post_id).slideUp('slow', function() {
				$(_this).remove();
			});
		});
	},

	leave_delete_v : function(post_id) {
		var _is_deleted = false;

		iwk_leave.del(post_id, function() {
			$("#view_wrap").empty().html(
					'<div style="padding:10px 0;"><a href="' + ''
							+ '">返回首页</a></div>');
			_is_deleted = true;
		}, function() {
			if (_is_deleted) {
				zebra_alert("删除成功!");
			}
		});
	},

	// 审核按钮
	audit : function(_this, _post_id, _flowid, _state, callback) {
		var _data = {
			"postid" : _post_id
		};
		_data.state = _state;
		_data.flowid = _flowid;
		_data.type = "state";

		if (iwk_leave.sending) {
			return;
		}

		iwk_leave.sending = 1;
		$.post('' + 'apps/flow/ajax/update/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			if (res.status.toLowerCase() == 'ok') {
				callback();
			} else {
				zebra_alert(res.message);
			}
			iwk_leave.sending = 0;
		}, 'json');
	},

	leave_audit : function(_this, _post_id, _flowid, _state) {
		iwk_leave.audit(_this, _post_id, _flowid, _state, function() {
			if (iwk_cfg.page_name == 'view') {
				iwk_post.synchronize_single(_post_id);
			} else {
				iwk_post.synchronize();
			}
		});
	},

	leave_audit_v : function(_this, _post_id, _flowid, _state) {
		iwk_leave.audit(_this, _post_id, _flowid, _state, function() {
			view_refresh_callback();
		});
	},

	// 打回按钮
	callback : function(_this, _post_id, _flowid, callback) {
		var _data = {
			"postid" : _post_id
		};
		_data.flowid = _flowid;
		_data.type = "back";
		$.post('' + 'apps/flow/ajax/update/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			if (res.status.toLowerCase() == 'ok') {
				callback();
			}
			zebra_alert(res.message);
		}, 'json');
	},

	leave_callback : function(_this, _post_id, _flowid) {
		iwk_leave.callback(_this, _post_id, _flowid, function() {
			if (iwk_cfg.page_name == 'view') {
				iwk_post.synchronize_single(_post_id);
			} else {
				iwk_post.synchronize();
			}
		});
	},

	leave_callback_v : function(_this, _post_id, _flowid) {
		iwk_leave.callback(_this, _post_id, _flowid, function() {
			view_refresh_callback();
		});
	},

	// 转发按钮
	transfer : function(_postid, _flowid) {

		$.fancybox({
			'modal' : false,
			'scrolling' : 'no',
			'href' : '#foot_common_user_picker',
			'helpers' : {
				overlay : {
					opacity : 0.2
				}
			},
			'beforeLoad' : function() {
				$("#fcup_multipicker").userpicker("clear");
				$("#foot_common_user_picker .btn").hide();
				$("#fcup_btn_leave").show();
				$("#fcup_textarea").val('').hide();
				$("#fcup_ipt_a, #fcup_ipt_b").val('');
				$("#fcup_ipt_a").val(_postid);
				$("#fcup_ipt_b").val(_flowid);
			}
		});
	},

	leave_transfer : function(_postid, _flowid) {
		iwk_leave.transfer(_postid, _flowid);
	},

	leave_transfer_v : function(_postid, _flowid) {
		iwk_leave.transfer(_postid, _flowid, 'view');
	},

	// 转发确定
	leave_transfer_ok : function() {
		var _r = $("#fcup_multipicker").userpicker("getData");
		if (_r.user && _r.user[0]) {
			$.fancybox.close();

			var _data = {
				"uid" : _r.user[0],
				"type" : "transfer"
			};
			_data.postid = $("#fcup_ipt_a").val();
			_data.flowid = $("#fcup_ipt_b").val();
			_data.text = $("#fcup_textarea").val();

			$.post('' + 'apps/flow/ajax/update/r:'
					+ Math.round(Math.random() * 1000), _data, function(res) {
				if (res.status.toLowerCase() == 'ok') {
					if (iwk_cfg.page_name == 'view') {
						iwk_post.synchronize_single(_data.postid);
					} else {
						iwk_post.synchronize();
					}
				}
				zebra_alert(res.message);
			}, 'json');
		} else {
			zebra_alert("请选择用户!");
		}
	}
};

// 任务JS对象
var iwk_task = {
	edit : function(postid, callback_after) {
		var _data = {
			"postid" : postid
		};
		$.post('' + 'apps/task/ajax/taskform-loadtask/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			if (callback_after)
				callback_after(res);

		}, 'json');
	},
	del : function(postid, callback_after, callback_onclose) {
		zebra_confirm(iwk_lng.task_delete_confirm_msg, function() {
			var _data = {
				"postid" : postid
			};
			$.post('' + 'apps/task/ajax/deltask/r:'
					+ Math.round(Math.random() * 1000), _data, function(res) {
				if ($.trim(res.toLowerCase()) == "ok")
					callback_after();
				else
					zebra_alert(iwk_lng.delete_error);
				$.fancybox.close();
			});
		}, null, callback_onclose);
	},
	// 删除单条发贴按钮(自己的发贴)
	task_delete : function(_this, post_id) {
		iwk_task.del(post_id, function() {
			$("#sp_" + post_id).slideUp('slow', function() {
				$(_this).remove();
			});
			$(_this).closest(".task_delete").remove();
		});
	},

	task_delete_v : function(post_id) {
		var _is_deleted = false;

		iwk_task.del(post_id, function() {
			var http_referer = $('#http_referer').val();
			if (http_referer != '') {
				window.location.href = http_referer;
				return false;
			}
			$("#view_wrap").empty().html(
					'<div style="padding:10px 0;"><a href="' + ''
							+ '">返回首页</a></div>');
			_is_deleted = true;
		}, function() {
			if (_is_deleted) {
				zebra_alert("删除成功!");
			}
		});
	},

	send_child_task : function() {
		var post_temp_id = iwk_cfg_postform.temp_id;
		;
		var _data = {
			"post_temp_id" : post_temp_id,
			"message" : ""
		};

		var _groupid = $("#child_group_id").val();
		_data.groupid = _groupid;

		if (iwk_cfg_postform.to.scope == iwk_cfg_postform.const_scope.group) {
			_data.groupid = iwk_cfg_postform.to.id;
		} else if (iwk_cfg_postform.to.scope == iwk_cfg_postform.const_scope.user) {
			_data.userid = iwk_cfg_postform.to.id;
		}
		if (iwk_cfg_postform.post_id != 0) {
			var id = iwk_cfg_postform.post_id.split("_");
			if (id != null && $(id).size() > 1 && id[1] > 0) {
				_data.editpost = iwk_cfg_postform.post_id;
			}
		}

		if (iwk_cfg_postform.edit == 1) {
			_data.editpost = iwk_cfg_postform.temp_id;
		}

		var msg = $("#child_pf_task_message").val();
		if (msg != "") {
			_data.message = msg;
		} else {
			zebra_alert(iwk_lng.msg_empty_alert);
			return;
		}

		// 获取任务执行人
		var _pk = $("#child_task_user_picker").userpicker("getData");
		if (_pk.number == 0) {
			zebra_alert(iwk_lng.task_assign_empty);
			return;
		} else {
			_data.assign_user = _pk.user;
			_data.assign_group = _pk.group;
			_data.assign_org = _pk.org;
		}

		//
		var child_is_whole = $("#child_is_whole").attr("checked");
		if (child_is_whole == "checked") {
			_data.is_whole = 1;
		} else {
			_data.is_whole = 0;
		}

		var startdate = $("#child_postform_task_begin").val();
		if (startdate != "") {
			_data.startdate = iwk_common.get_timestamp(startdate);
		}
		var enddate = $("#child_postform_task_end").val();
		if (enddate != "") {
			_data.enddate = iwk_common.get_timestamp(enddate);
		} else {
			zebra_alert(iwk_lng.task_enddate_empty);
			return;
		}

		_data.r_state = 0;

		var priority = $("#child_priority").find(
				"input[name=iwk_pulldown_select]").val();
		if (priority != "" || priority == "0") {
			_data.priority = priority;
		}

		var parent = $("#pf_parent_task_id").val();
		if (parent != "") {
			_data.parent = parent;
		}

		iwk_cfg_postform.sending = 1;
		$.post('' + 'apps/task/ajax/taskform-submit/ajaxtp:xml/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			var _st = res.status.toLowerCase();
			if (_st == "ok") {
				iwk_task.init_child_task_data();
			} else if (_st == "error") {
				zebra_alert(res.message);
				iwk_cfg_postform.sending = 0;
			} else {
				zebra_alert(iwk_lng.edit_error);
				iwk_cfg_postform.sending = 0;
			}
		}, 'json');
	},
	// 初始化数据，并异步调用列表
	init_child_task_data : function() {
		iwk_postform.init_postform_cfg();
		$("#child_remind_type_email").attr("checked", "checked");
		$("#child_postform_task_begin").val("");
		$("#child_postform_task_end").val("");
		$("#child_remind_switch_close").attr("checked", "checked");
		$("#child_remind_switch_open").removeAttr("checked");
		$("#child_remind_type_email").attr("checked", "checked");
		$("#child_remind_type_mobile").attr("checked", "checked");
		$("#child_remind_date").find("input[name=iwk_pulldown_select]")
				.val("0");
		$("#child_remind_date").find("span").html(iwk_lng.task_tip_r_date);
		$("#child_remind_interval").find("input[name=iwk_pulldown_select]")
				.val("0");
		$("#child_remind_interval").find("span").html(
				iwk_lng.task_tip_r_interval);
		$("#child_repeating_time").find("input[name=iwk_pulldown_select]").val(
				"0");
		$("#child_repeating_time").find("span").html(iwk_lng.task_tip_repeat);
		$("#child_priority").find("input[name=iwk_pulldown_select]").val("0");
		$("#child_priority").find("span").html(iwk_lng.task_tip_priority);

		$("#child_pf_task_message").val("");
		$(".iwk_postform_attachs").empty();
		iwk_post.synchronize();
		iwk_task.p_f_close();
	},
	task_form_show : function(_this) {
		$.fancybox({
			'modal' : true,
			'scrolling' : 'visible',
			'href' : '#postform_project_task',
			'helpers' : {
				overlay : {
					opacity : 0.2
				}
			},
			'beforeLoad' : function() {
				$(".iwk_postform_foot").show();
			}
		});
	},

	// 任务高级选项 - 全天勾选事件
	task_options_datetime_toggle : function(_this) {
		if ($(_this).find("span").hasClass("checked")) {
			$("#pf_child_opts_datetime_line").fadeIn();
			$("#pf_child_opts_today").show();
			$("#pf_child_opts_datetime_whole").fadeOut();
		} else {
			$("#pf_child_opts_datetime_line").fadeOut();
			$("#pf_child_opts_today").hide();
			$("#pf_child_opts_datetime_whole").fadeIn();
		}
	},

	// 任务高级选项 - 提醒开
	task_options_remind_open : function() {
		$("#pf_child_opts_remind_line").fadeIn();
	},

	// 任务高级选项 - 提醒关
	task_options_remind_close : function() {
		$("#pf_child_opts_remind_line").fadeOut();
	},
	// 删除单条任务
	task_delete_single : function(_this) {
		var _pid = $(_this).attr("data_p");
		var _pcid = $(_this).attr("data_pc");
		var _post = $("#sp_" + _pid);
		iwk_post
				.del_reply(
						_pid,
						_pcid,
						function() {
							var _data = {
								"post_id" : _pid
							};
							$
									.post(
											''
													+ 'ajax/single_post_synchronize/r:'
													+ Math
															.round(Math
																	.random() * 1000),
											_data,
											function(txt) {
												if (txt.substr(0, 3) != "OK:") {
													return;
												}
												txt = txt.replace(/^OK\:/, "");
												txt = $($.trim(txt));
												var cnt = txt
														.find(
																".single_post_comment")
														.find(
																".single_post_comment_cnt").length;
												// 先更新数字
												_post
														.find(
																".single_post_comment_pf_info")
														.html(
																txt
																		.find(
																				".single_post_comment_pf_info")
																		.html());
												_post
														.find(
																".single_post_func_reply")
														.html(
																txt
																		.find(
																				".single_post_func_reply")
																		.html());
												if (cnt == 0)
													_post
															.find(
																	".single_post_comment")
															.slideUp(
																	"slow",
																	function() {
																		_post
																				.find(
																						".single_post_comment")
																				.html(
																						txt
																								.find(
																										".single_post_comment")
																								.html());
																	});
												else
													$("#spc_" + _pcid)
															.slideUp(
																	"slow",
																	function() {
																		_post
																				.find(
																						".single_post_comment")
																				.html(
																						txt
																								.find(
																										".single_post_comment")
																								.html());
																	});
											});
						});
	},

	// 完成任务
	finish : function(posttmpid, taskid, state, is_tip, callback) {
		if (!iwk_cfg.task_sending) {
			iwk_cfg.task_sending = {};
		}
		if (iwk_cfg.task_sending[posttmpid]) {
			return;
		}
		if (is_tip == 1) {
			if (state == 1) {
				zebra_confirm("是否确认任务全部完成？", function() {
					iwk_task.finish_ok(posttmpid, taskid, state, function() {
						callback();
					});
				});
			} else {
				zebra_confirm("是否确认任务全部重启？", function() {
					iwk_task.finish_ok(posttmpid, taskid, state, function() {
						callback();
					});
				});
			}
		} else {
			iwk_task.finish_ok(posttmpid, taskid, state, function() {
				callback();
			});
		}

	},

	finish_ok : function(posttmpid, taskid, state, callback) {
		iwk_cfg.task_sending[posttmpid] = 1;
		// 阻塞
		fancylay.block();

		var pid = posttmpid.split("_");
		var p = "type=state&state=" + state + "&taskid=" + taskid + "&postid="
				+ pid[1];
		$.post('' + 'apps/task/ajax/update-task/r:'
				+ Math.round(Math.random() * 1000), p, function(res) {
			if (res != null && res.reload) {
				window.location.reload();
				return;
			}
			if (res.status.toLowerCase() == 'ok') {
				callback();
				fancylay.unblock();
			} else {
				fancylay.unblock();
				zebra_alert(res.message);
			}
			iwk_cfg.task_sending[posttmpid] = 0;
		}, 'json');
	},

	task_finish : function(posttmpid, taskid, state, is_tip) {
		iwk_task.finish(posttmpid, taskid, state, is_tip, function() {
			if (state == 1) {
				zebra_alert("任务已完成!");
			}
			iwk_post.synchronize_single(posttmpid);
		});
	},

	task_finish_v : function(posttmpid, taskid, state) {
		iwk_task.finish(posttmpid, taskid, state, function() {
			var msg = '';
			if (state == 1) {
				msg = '任务已完成!';
			} else {
				msg = '任务已打回!';
			}
			view_refresh_callback(msg);
		});
	},

	// 转发按钮
	transfer : function(_postid) {

		$.fancybox({
			'modal' : false,
			'scrolling' : 'no',
			'href' : '#foot_task_trans_picker',
			'helpers' : {
				overlay : {
					opacity : 0.2
				}
			},
			'beforeLoad' : function() {

				$("#fttp_multipicker").userpicker("clear");
				$("#fttp_textarea").val('');
				$("#fttp_ipt_a").val(_postid);

				$.get('' + 'apps/task/ajax/assign_users/r:'
						+ Math.round(Math.random() * 1000), {
					postid : _postid
				}, function(res) {
					if (res.status == 'OK') {
						$("#fttp_multipicker").userpicker("reload", {
							filterUser : res.info,
							disableOrg : true
						});
					} else {
						$("#fttp_multipicker").userpicker("reload", {
							filterUser : [],
							disableOrg : true
						});
					}
				}, 'json');
			}
		});
	},

	task_transfer : function(_postid) {
		iwk_task.transfer(_postid);
	},

	task_transfer_v : function(_postid) {
		iwk_task.transfer(_postid, 'view');
	},

	// 转发确定
	task_transfer_ok : function() {
		var _r = $("#fttp_multipicker").userpicker("getData");
		if (_r.user && _r.user[0]) {
			$.fancybox.close();

			var _data = {
				"uid" : _r.user[0],
				"type" : "transfer"
			};
			_data.postid = $("#fttp_ipt_a").val();
			_data.text = $("#fttp_textarea").val();
			// 阻塞
			fancylay.block();
			$.post('' + 'apps/task/ajax/update-task/r:'
					+ Math.round(Math.random() * 1000), _data, function(res) {
				if (res.status.toLowerCase() == 'ok') {
					if (iwk_cfg.page_name == 'view') {
						var _pid = 'public_' + _data.postid;
						iwk_post.synchronize_single(_pid);
					} else {
						iwk_post.synchronize();
					}
				}
				fancylay.unblock();
				zebra_alert(res.message);
			}, 'json');
		} else {
			zebra_alert("请选择用户!");
		}
	},

	show_or_hide : function(obj) {
		// $(obj).parent().next().show();
		var _wrap = $(obj).parent().next();
		_wrap.slideToggle(function() {

		});
	},
	// 因ID不能在同一个页面使用多次，这里重新写一个以class获取的方法 在项目中使用
	send_p_task : function() {
		var post_temp_id = iwk_cfg_postform.temp_id;
		var _data = {
			"post_temp_id" : post_temp_id,
			"message" : ""
		};

		var _groupid = $(".prj_group_id").val();
		_data.groupid = _groupid;

		if (iwk_cfg_postform.to.scope == iwk_cfg_postform.const_scope.group) {
			_data.groupid = iwk_cfg_postform.to.id;
		} else if (iwk_cfg_postform.to.scope == iwk_cfg_postform.const_scope.user) {
			_data.userid = iwk_cfg_postform.to.id;
		}
		if (iwk_cfg_postform.post_id != 0) {
			var id = iwk_cfg_postform.post_id.split("_");
			if (id != null && $(id).size() > 1 && id[1] > 0) {
				_data.editpost = iwk_cfg_postform.post_id;
				_data.removed_attaches = iwk_cfg_postform.removed_attaches
						.join(",");
			}
		}

		var msg = $(".pf_task_message").val();
		if (msg != "") {
			_data.message = msg;
		} else {
			zebra_alert(iwk_lng.msg_empty_alert);
			return;
		}

		// 任务执行人
		var _pk = $(".task_user_picker").userpicker("getData");
		if (_pk.number == 0) {
			zebra_alert(iwk_lng.task_assign_empty);
			return;
		} else {
			_data.assign_user = _pk.user;
			_data.assign_group = _pk.group;
			_data.assign_org = _pk.org;
		}

		if ($(".is_whole").is(":checked")) {
			_data.is_whole = 1;
		} else {
			_data.is_whole = 0;
		}

		// 开始结束时间
		var startdate = $(".postform_task_begin").val();
		var enddate = $(".postform_task_end").val();
		var limit_day = $('.postform_task_worktime').val()
		if (limit_day != '') {
			_data.limit_day = limit_day;
		}
		_data.startdate = iwk_common.get_timestamp($(".postform_task_begin")
				.val());
		_data.enddate = iwk_common.get_timestamp($(".postform_task_end").val());

		if (startdate > enddate) {
			zebra_alert(iwk_lng.task_date_over);
			return;
		}

		var priority = parseInt($(".priority").find(
				"input[name=iwk_pulldown_select]").val());
		if (isNaN(priority)) {
			_data.priority = 0;
		} else {
			_data.priority = priority;
		}

		var prjid = $(".pf_project_id").val();
		if (prjid != "" || prjid == "0") {
			_data.prjid = prjid;
		}
		var customerid = $(".pf_customer_id").val();
		if (customerid != "" || customerid == "0") {
			_data.customerid = customerid;
		}
		iwk_cfg_postform.sending = 1;
		$.post('' + 'apps/task/ajax/taskform-submit/ajaxtp:xml/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			var _st = res.status.toLowerCase();
			if (_st == "ok") {
				iwk_task.p_task_data();
			} else if (_st == "error") {
				zebra_alert(res.message);
				iwk_cfg_postform.sending = 0;
			} else {
				zebra_alert(iwk_lng.edit_error);
				iwk_cfg_postform.sending = 0;
			}
		}, 'json');
	},
	// 初始化
	p_task_data : function() {
		$.fancybox.close()
		iwk_post.synchronize();
		iwk_cfg_postform.sending = 0;

		$('.pf_task_message').val('');
		iwk_postform.init_postform_cfg();
		iwk_postform.show_type(true);
		iwk_postform.task_object_show();
		$(".task_user_picker").find("li").remove();
		$('.postform_task_worktime').val('');
		$('.options_wrap').hide();

	},
	// 取消按钮
	p_f_close : function() {
		iwk_task.p_task_data();
	},

	load_evaluate : function(_this, _posttmpid) {
		var pid = _posttmpid.split("_");
		var _data = {
			type : 'readeval',
			"postid" : pid[1]
		};
		$.post('' + 'apps/task/ajax/update-task/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			if (res != null && res.status.toLowerCase() == "ok") {
				if (res.data.point > 0) {
					$("#form_task_point").val(res.data.point);
				}
				$("#form_task_evaluate_desc").val(res.data.content);
			}
		}, 'json');
	},
	// 显示任务评价
	evaluate_form_show : function(_this, _pid) {
		$
				.fancybox({
					'modal' : true,
					'scrolling' : 'visible',
					'href' : '#iwk_task_form_evaluate',
					'helpers' : {
						overlay : {
							opacity : 0.2
						}
					},
					'beforeLoad' : function() {
						$("#form_task_evaluate_pid").val(_pid);
						iwk_task
								.edit(
										_pid,
										function(res) {
											if (res != null) {
												var _data = res.post;
												var i, j;
												var _container = $("#evaluate_container");
												var _template = $("#_evaluate_template");

												_container.empty();
												if (_data.assigns != null) {
													for (i = 0; i < _data.assigns.length; i++) {
														var _user = _data.assigns[i];
														var _u_input = _template
																.find("input[name=evaluate_users]");
														var _u_name = _template
																.find(".single_customer_col_name span");
														var _u_point = _template
																.find("input[name=evaluate_points]");
														var _u_desc = _template
																.find("input[name=evaluate_descs]");
														var _evl_index = -1;
														var _evl_data = false;

														$
																.each(
																		_data.evaluates,
																		function(
																				j,
																				evl) {
																			if (_user.id == evl.assign_user) {
																				_evl_index = j;
																				_evl_data = evl;
																				return;
																			}
																		});
														_u_name
																.html(_data.assigns[i].fullname);
														_u_input
																.val(_data.assigns[i].id);
														if (_evl_index >= 0) {
															_u_point
																	.val(_evl_data.point);
															_u_desc
																	.val(_evl_data.evaluate_desc);
														}
														var $contact = _template
																.find(
																		"div.single_customer_wrap")
																.clone().show();
														_container
																.append($contact);
														_container
																.find(
																		"input[name=evaluate_points]")
																.onefloatinput();
														// _u_point.decimalinput();
													}
												}
											}

										});

					},
					'beforeShow' : function() {
						// iwk_task.load_evaluate(_this, _pid);
					}
				});
	},

	// 提交评价
	evaluate_task : function() {
		var _posttmpid = $("#form_task_evaluate_pid").val();
		if (_posttmpid == null || _posttmpid == "") {
			zebra_alert(iwk_lng.plan_not_select);
			return;
		}
		var pid = _posttmpid.split("_");
		var _users = new Array();
		var _points = new Array();
		var _contents = new Array();
		var _data = {
			type : 'evaluate',
			postid : pid[1]
		};

		var _user_index = 0;
		$("#evaluate_container").find("input[name=evaluate_users]").each(
				function() {
					_users[_user_index] = $(this).val();
					_user_index++;
				});

		var _point_index = 0;
		$("#evaluate_container").find("input[name=evaluate_points]").each(
				function() {
					_points[_point_index] = $(this).val();
					_point_index++;
				});

		var _desc_index = 0;
		$("#evaluate_container").find("input[name=evaluate_descs]").each(
				function() {
					_contents[_desc_index] = $(this).val();
					_desc_index++;
				});

		var i;
		if (_points != "") {
			for (i = 0; i < _points.length; i++) {
				if (_points[i] < 0 || _points[i] > 10) {
					zebra_alert(iwk_lng.plan_error_point);
					return;
				}
			}
		}

		if (_users != "") {
			_data.users = _users;
			_data.points = _points;
			_data.contents = _contents;
			var _is_input_val = false;
			for ( var i = 0; i < _points.length; i++) {
				if (_points[i] != "") {
					_is_input_val = true;
				}
			}
			;
			for ( var i = 0; i < _contents.length; i++) {
				if (_contents[i] != "") {
					_is_input_val = true;
				}
			}
			;
			if (!_is_input_val) {
				zebra_alert(iwk_lng.task_evaluate_empty);
				return false;
			}
		}

		fancylay.block();
		$.post('' + 'apps/task/ajax/update-task/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			if (res.status.toLowerCase() == 'ok') {
				iwk_post.synchronize_single(_posttmpid);
			} else {
				zebra_alert(res.message);
			}
			fancylay.unblock();
			$.fancybox.close();
		}, 'json');

	}

};

var iwk_customer = {
	edit : function(postid, callback_after) {
		var _data = {
			"postid" : postid
		};
		$.post('' + 'apps/customer/ajax/cus-formload/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			if (callback_after)
				callback_after(res);
		}, 'json');
	},

	edit_data : function(obj) {

		iwk_cfg_postform.post_id = 'public_' + $(obj).attr('data');

		// 重置状态
		$('.iwk_postform_attachs').empty();

		var postid = $(obj).attr('data');

		var _data = {
			"postid" : postid
		};

		$.post(''
				+ 'apps/customer/ajax/cus-formsubmit/action:update/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			rsn = eval('(' + res + ')');
			if (rsn._status == 'ok') {
				var rn = rsn._res;
				$("#customer_name").val(rn.cr.customer_name);
				$("#contact").val(rn.cr.link_man);
				$("#link_phone").val(rn.cr.link_phone);
				$("#pf_customer_textarea").val(rn.pr.note);

				$("#link_position").val(rn.cr.link_position);
				$("#email").val(rn.cr.link_email);
				$("#address").val(rn.cr.address);

				$("#postform_body_post").show();
				$("#iwk_customer_postform").show();

				if (rn.ar != 0) {

					$.each(rn.ar.attaches, function(i, n) {

						var _id = n.id;
						var _type = n.type;
						var _filename = n.filename;
						var keyy = iwk_common.get_new_guid();
						iwk_cfg_postform.temp_data = {
							keyy : keyy,
							filename : _filename
						};
						iwk_postform.append_attach_to_view(_type,
								iwk_cfg_postform.temp_data.filename, '', _id);
					});
				}

				$('#reset_editor_id').show();

				$('#manager_user_picker').find('li').attr('data', rn.fzr.id);
				$('#manager_user_picker').find('.name').text(rn.fzr.fullname);

				$('#customer_user_picker').html('');

				if (rn.csr == null) {
					$("#customer_user_picker").userpicker({
						placeholder : "+ 抄送用户",
						hint : "请输入搜索过滤"
					});

				} else {

					$('#customer_user_picker').userpicker({
						placeholder : "+ 抄送用户",
						hint : "请输入搜索过滤",
						showGroup : true,
						showOrg : true,
						multi : true,
						defaultUser : rn.csr
					});

				}
			} else {
				zebra_alert(rsn._msg);
				return false;
			}
		});

	},

	// 取消编辑
	cancel_edit : function() {
		iwk_customer.init_form_data("postform_body_customer");
		$.fancybox.close();
	},

	del : function(postid, callback_after) {
		zebra_confirm(iwk_lng.customer_delete_confirm_msg, function() {
			var _data = {
				"postid" : postid
			};
			$.post('' + 'apps/customer/ajax/cus-delete/r:'
					+ Math.round(Math.random() * 1000), _data, function() {
				if (callback_after)
					callback_after();
			});
		});
	},
	// 删除单条发贴按钮(自己的发贴)
	customer_delete : function(_this, post_id) {
		iwk_customer.del(post_id, function() {
			$("#sp_" + post_id).slideUp('slow', function() {
				$(_this).remove();
			});
		});
	},
	// 发送客户
	send_customer : function(obj) {

		// var y_num = new RegExp("^[0-9]*$");
		// var y_email =
		// /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
		var y_email = /^[a-zA-Z0-9._%-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z]{2,4}$/;

		if (iwk_cfg_postform.attach_sending) {
			zebra_alert(iwk_lng.attach_is_sending_msg);
			return;
		}
		if (iwk_cfg_postform.sending) {
			zebra_alert(iwk_lng.is_sending_msg);
			return;
		}

		var _msg = $.trim($("#pf_customer_textarea").val());
		var _data = {
			"post_temp_id" : iwk_cfg_postform.temp_id,
			"message" : _msg
		};

		if (_msg !== "") {
			_data.message = _msg;
		}

		var _manager = $("#customer_manager_picker").userpicker("getData");
		if (_manager.number != 0) {
			_data.manager = _manager.user[0];
		} else {
			zebra_alert(iwk_lng.customer_empty_manager);
			return;
		}

		// 类型
		var _customertype = $('#pf_customer_type').pulldown2('getVal');
		if (_customertype && _customertype.res) {
			_data.customer_type = _customertype.res;
		}

		var _name = $.trim($("#customer_name").val());
		if (_name != "") {
			_data.customer_name = _name;
			if (_name.length > 30) {
				zebra_alert('客户名称过长');
				return;
			}
		} else {
			zebra_alert(iwk_lng.customer_empty_name);
			return;
		}

		var _contact = $.trim($("#customer_contact").val());
		if (_contact != "") {
			_data.contact = _contact;
		} else {
			zebra_alert(iwk_lng.customer_empty_contact);
			return;
		}

		var _link_phone = $.trim($("#customer_link_phone").val());
		if (_link_phone != "") {
			_data.phone = _link_phone;
		} else {
			zebra_alert(iwk_lng.customer_empty_phone);
			return;
		}

		// 其他联系人
		var $container = $("#__cus_contact_container__");
		var $other_contacts = $container.find("div.__cus_contact__");
		if ($other_contacts.length > 0) {
			var _contact_names = [];
			var _contact_phones = [];
			var _contact_positions = [];
			var _contact_emails = [];
			var _contact_indexs = [];
			var j = 0;
			$.each($other_contacts, function(i, v) {
				var _contact_name = $.trim($(v).find(
						"input[name='customer_contact']").val());
				var _contact_phone = $.trim($(v).find(
						"input[name='customer_link_phone']").val());
				var _contact_position = $.trim($(v).find(
						"input[name='customer_link_position']").val());
				var _contact_email = $.trim($(v).find(
						"input[name='customer_email']").val());
				var _contact_index = $.trim($(v).find(
						"font[name='__cus_contact_index__']").text());
				if (_contact_name != '' && _contact_phone != '') {
					_contact_names[j] = _contact_name;
					_contact_phones[j] = _contact_phone;
					_contact_positions[j] = _contact_position;
					_contact_emails[j] = _contact_email;
					_contact_indexs[j] = _contact_index;
					j++;
				}
			});
			_data.contact_name = _contact_names;
			_data.contact_phone = _contact_phones;
			_data.contact_position = _contact_positions;
			_data.contact_email = _contact_emails;
			_data.contact_index = _contact_indexs;
		}

		var _otherman = $("#customer_other_picker").userpicker("getData");
		if (_otherman.number == 0) {

		} else {
			_data.assign_user = _otherman.user;
			_data.assign_group = _otherman.group;
			_data.assign_org = _otherman.org;
		}

		var _link_position = $.trim($("#customer_link_position").val());
		if (_link_position != "") {
			_data.link_position = _link_position;
		}

		var _email = $.trim($("#customer_email").val());
		if (_email != "") {
			if (!y_email.test(_email)) {
				zebra_alert('邮箱格式不正确');
				return;
			}
			_data.email = _email;
		}

		var _address = $.trim($("#customer_address").val());
		if (_address != "") {
			_data.address = _address;
		}

		if (iwk_cfg_postform.post_id != 0) {
			var id = iwk_cfg_postform.post_id.split("_");
			if (id != null && $(id).size() > 1 && id[1] > 0) {
				_data.editpost = iwk_cfg_postform.post_id;
				_data.removed_attaches = iwk_cfg_postedit.removed_attaches
						.join(",");
			}
		}

		if (iwk_cfg_postform.post_id != 0) {
			var id = iwk_cfg_postform.post_id.split("_");
			if (id != null && $(id).size() > 1 && id[1] > 0) {
				_data.editpost = iwk_cfg_postform.post_id;
			}
		}

		// 客户地址经纬度
		var _lng_val = $("#pr_customer_Longitude").val();
		var _lat_val = $("#pr_customer_Latitude").val();
		if (_lng_val != "" && _lat_val != "") {
			_data.lng = _lng_val;
			_data.lat = _lat_val;
		}

		$.post(''
				+ 'apps/customer/ajax/cus-formsubmit/ajaxtp:xml/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			var _st = res;
			if (_st._status == "OK") {

				$('#iwk_postform_attachs').empty();

				if ($(obj).attr('ty') == 'update') {
					$.fancybox.close();
					window.location.href = document.URL;
					// return false;
				} else {
					iwk_cfg_postform.sending = 0;
				}

			} else {
				zebra_alert(_st._msg);
				$.fancybox.close();
				iwk_cfg_postform.sending = 0;
				return false;
			}
			// iwk_post.synchronize();
			iwk_customer.init_edit_window_data();
			window.location.href = document.URL;
		}, 'json');
	},

	init_form_data : function(id) {

		var obj = $('#' + id);
		obj.find(".pf_user_id").val("");
		$("#pf_customer_textarea").val("");
		$("#customer_name").val("");
		$("#customer_contact").val("");
		$("#customer_link_phone").val("");
		$("#customer_link_position").val("");
		$("#customer_email").val("");
		$("#customer_address").val("");
		$("#customer_manager_picker").html("");
		$('#customer_other_picker').html('');
		$("#customer_manager_picker").userpicker({
			placeholder : "+ 添加客户负责人",
			hint : "请输入搜索过滤",
			multi : false,
			defaultUser : [ {
				data : iwk_cfg.my_id,
				name : iwk_cfg.my_name
			} ]
		});
		$("#customer_other_picker").userpicker({
			placeholder : "+ 添加可查看用户",
			hint : "请输入搜索过滤",
			withSpecialGroup : iwk_cfg.is_show_special_group,
			defaultUser : [ {
				data : iwk_cfg.my_id,
				name : iwk_cfg.my_name
			} ]
		});
		iwk_cfg_postform.temp_at_file = 0;
		iwk_cfg_postform.post_id = 0;
		$.fancybox.close();
	},

	close : function(obj) {
		var id = $(obj).attr('ac_id');
		iwk_customer.init_form_data(id);
	},

	show_more : function(obj) {
		$(obj).parent().parent().find('.prj_show_more').toggle();
	},

	// 显示任务高级选项
	customer_options_show : function(_this) {
		var _wrap = $("#postform_customer_options_wrap");
		iwk_postform.toggle_options(_wrap, _this);
	},
	customer_options_show_edit : function(_this) {
		iwk_customer.add_one_contact_edit();
		iwk_customer.customer_options_show();
	},

	show_add_customer : function() {
		iwk_customer.clear_all_contacts();
		$("#iwk_postform").toggle();
	},
	clear_all_contacts : function() {
		var _container = $("#__cus_contact_container__");
		_container.empty();
	},
	remove_contact : function(_this) {		
		$($(_this).parents('div.add_template')[0]).remove();
		if($('#__edit_cus_contact_container__').find('.add_template').length==0){
			$('#__edit_cus_contact_container__').attr('style','display:none');
		}
	},
	// 添加其他联系人
	add_one_contact : function() {
		var $container = $("#__cus_contact_container__");
		var $template = $("#__cus_contact_template__");
		var $count = $container.find("div.__cus_contact__").length;
		if ($count == 0) {
			$count++;
		} else {
			$count = $container.find("div.__cus_contact__:last").find(
					"font[name='__cus_contact_index__']").text();
			$count = Number($count) + 1;
		}
		var $contact = $template.find("div.__cus_contact__").clone().show();
		$contact.find("font[name='__cus_contact_index__']").text($count);
		$container.append($contact);
		$container.get(0).scrollTop = $container.get(0).scrollHeight;
	},
	// 添加其他联系人
	add_one_contact_edit : function() {
		var $container = $("#__edit_cus_contact_container__");
		var $template = $("#__edit_cus_contact_template__").children();
		if ($(".add_template").length >= 6) {
			return false;
		}
		$container.append($template.clone());
		$container.show();
		$container.scrollTop($container.height() + $container.scrollTop());
		$(
				"div.fancybox-wrap.fancybox-desktop.fancybox-type-inline.fancybox-opened")
				.resize();
	},
	// 弹出客户编辑界面
	show_edit_customer : function(obj) {
		$.fancybox.showLoading();
		iwk_cfg_postform.post_id = 'public_' + $(obj).attr('data');

		// 重置状态
		$("#iwk_postedit_attachs").empty();
		var _pid = $(obj).attr('data');
		var _t = $(obj).attr('act');
		var _data = {
			postid : _pid
		};

		// 加载附件
		$
				.post(
						''
								+ 'apps/customer/ajax/cus-formsubmit/ajaxtp:xml/action:update/r:'
								+ Math.round(Math.random() * 1000), _data,
						function(res) {
							var rn = eval('(' + res + ')');
							if (rn._status == 'ok') {
								iwk_cfg_postform.post_id = 'public_' + _pid;
								iwk_customer.customer_load(rn);
							} else {
								if (rn._type == 1) { // 没有权限
									zebra_alert(rn._msg);
									iwk_customer.cancel_edit();
								}
							}
						});

		$.fancybox({
			'modal' : true,
			'autoSize' : true,
			'autoWidth' : true,
			'autoHeight' : true,
			'scrolling' : 'visible',
			'href' : '#iwk_customer_postform_editor',
			'helpers' : {
				overlay : {
					opacity : 0.2
				}
			},
			'beforeLoad' : function() {

			},
			'afterShow' : function() {
				$("#cancel_edit_customer").show();
			},
			'afterClose' : function() {
				iwk_customer.init_edit_window_data();
			}
		});
	},

	init_edit_window_data : function() {
		iwk_customer.init_form_data("postform_body_customer");
		$("#iwk_postform").hide();
		iwk_cfg_postform.sending = 0;
		$("#cancel_edit_customer").hide();
		$("#pr_customer_Longitude").val("");
		$("#pr_customer_Latitude").val("");
	},

	// 客户编辑加载数据
	customer_load : function(res) {

		var pr = res._res.pr;
		var cr = res._res.cr;
		var ar = res._res.ar;
		var fzr = res._res.fzr;
		var csr = res._res.csr;
		var gr = res._res.group;
		var ogr = res._res.org;

		$('#customer_name').val(cr.customer_name);
		$('#customer_contact').val(cr.link_man);
		$('#customer_link_phone').val(cr.link_phone);
		$('#pf_customer_textarea').val(cr.note);
		$('#customer_link_position').val(cr.link_position);
		$('#customer_email').val(cr.link_email);
		$('#customer_address').val(cr.address);
		$('#customer_other_picker').html('');
		$('#customer_manager_picker').html('');
		$('#customer_manager_picker').find('li').attr('data', fzr.id);
		$('#customer_manager_picker').find('.name').text(fzr.fullname);

		$("#customer_manager_picker").userpicker({
			placeholder : "+ 抄送用户",
			hint : "请输入搜索过滤",
			multi : false,
			defaultUser : [ {
				data : fzr.id,
				name : fzr.fullname
			} ]
		});
		if (csr == null) {
			$("#customer_other_picker").userpicker({
				placeholder : "+ 抄送用户",
				hint : "请输入搜索过滤",
				defaultGroup : gr
			});

		} else {

			$('#customer_other_picker').userpicker({
				placeholder : "+ 抄送用户",
				hint : "请输入搜索过滤",
				showGroup : true,
				showOrg : true,
				multi : true,
				defaultUser : csr
			});

		}

		// 附件
		if (ar != 0) {
			var attach = ar.attaches;
			$.each(attach, function(i, n) {
				var _id = n.id;
				var _type = n.type;
				var _filename = n.filename;
				iwk_postedit.append_attach_to_view(_id, _filename);
			});
		}
	},

	// 更新帖子状态
	post_proc : function(posttmpid, type, _pric_val, is_old_single) {
		var _data = {
			"postid" : posttmpid
		};
		_data.exec_type = type;
		_data.val = _pric_val;
		// zebra_confirm(iwk_lng.post_exec_comfirm, function(){
		$.post('' + 'ajax/post_update/r:'
				+ Math.round(Math.random() * 1000), _data,
				function(res) {
					if (res.status.toLowerCase() == 'ok') {
						zebra_auto('操作成功', 1000);
						iwk_post.morer_start_from = 10;
						if (is_old_single) {
							iwk_customer_edit.synchronize_single("public_"
									+ posttmpid);
						} else {
							iwk_post.synchronize();
						}
					} else {
						zebra_alert(res.message);
					}
				}, 'json');
		// }, null);
	},

	//弹出导入客户
	pop_add_customer : function(){
		$.fancybox({
    		modal: true,
    		scrolling: "visible",
    		padding:0,
    		href: "#add_customer_wrap",
    		helpers: {overlay: {opacity: 0.2}},
    		beforeLoad: function(){
    			
    		}
    	});
	},
	
	save_add_customer : function(){
		var _data = {"action": "add_member"};
		var _lines = $("#add_member_container li");
		var _array = new Array();
		var _is_valid = true;
		
		//重置错误提示
		_lines.find(".widget_ipt_lite_wrap").removeClass("error").find(".widget_ipt_lite_tip").remove();
		
		_lines.each(function(){
			var _line = $(this);
			var _fullname = $.trim(_line.find("input.fullname").val());
			var _mobile = $.trim(_line.find("input.mobile").val());
			
			//当姓名、手机有一个不为空才检查
			if(_fullname != "" || _mobile != ""){
				if(_fullname == ""){
					_is_valid = false;
					iwk_widget.add_error(_line.find(".widget_ipt_lite_wrap").eq(0), "请输入姓名");
				}else if(_mobile == ""){
					_is_valid = false;
					iwk_widget.add_error(_line.find(".widget_ipt_lite_wrap").eq(1), "请输入手机号");
				}else{
					var _tmp_data = {};
					_tmp_data.id = _line.attr("id");
					_tmp_data.fullname = _fullname;
					_tmp_data.mobile = _mobile;
					_array.push(_tmp_data);
				}
			}
		});
		
		//只有_line里面未检查到错误，才判断
		if(_is_valid && _array.length == 0){
			zebra_alert("请输入姓名和手机号/邮箱");
			return;
		}
		if(_is_valid){
			_data.members = _array;
		}else{
			return;
		}
		
		//是否开通用户
		if($("#is_active").is(":checked")){
			_data.is_active = 1;
		}else{
			_data.is_active = 0;
		}
		
		if(iwk_cfg_org.sending){return;}
		
		iwk_cfg_org.sending = 1;
		$.post(''+'ajax/org_member_oper/r:'+Math.round(Math.random()*1000), _data, function(res) {
			var _st = res.status;
			if(_st == "ok"){
				zebra_alert(res.message, function(){
					window.location.reload();
				});
			}else{
				if(typeof(res.error) == "object"){
					$.each(res.error, function(i, n){
						var _li = $("#"+n.id);
						if(n.fullname != ""){
							iwk_widget.add_error(_li.find(".widget_ipt_lite_wrap").eq(0), n.fullname);	
						}
						if(n.mobile != ""){
							iwk_widget.add_error(_li.find(".widget_ipt_lite_wrap").eq(1), n.mobile);
						}
					});
				}else{
					//这里处理系统错误
					zebra_alert(res.message);
				}
				iwk_cfg_org.sending = 0;
			}
		}, 'json');
	}
};

var iwk_project = {
	edit : function(postid, callback_after) {
		var _data = {
			"postid" : postid
		};
		$.post('' + 'apps/project/ajax/formload/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			if (callback_after)
				callback_after(res);
		}, 'json');
	},
	del : function(postid, callback_after) {
		zebra_confirm('删除此项目,确认?', function() {
			var _data = {
				"postid" : postid
			};
			$.post('' + 'apps/project/ajax/delproject/r:'
					+ Math.round(Math.random() * 1000), _data, function() {
				if (callback_after)
					callback_after();
			});
		});
	},
	// 删除单条发贴按钮(自己的发贴)
	project_delete : function(_this, post_id) {
		iwk_project.del(post_id, function() {
			$("#sp_" + post_id).slideUp('slow', function() {
				$(_this).remove();
			});
		});
	},
	show_add_project : function() {
		// if ($("#iwk_project_postform").is(":visible")){
		// $("#iwk_project_postform").hide();
		// }else{
		// $("#iwk_project_postform").show();
		// }
		$("#iwk_postform").toggle();
	},
	// 显示任务高级选项
	project_options_show : function(_this) {
		var _wrap = $("#postform_project_options_wrap");
		iwk_postform.toggle_options(_wrap, _this);
	},
	accordion : function(obj) {
		if ($(obj).html() == '-') {
			$(obj).html('+');
			$(obj).parent().parent().children('.report_proc_div_body').slideUp(
					300);
		} else {
			$(obj).html('-');
			$(obj).parent().parent().children('.report_proc_div_body')
					.slideDown(300);
		}
	},
	send_project : function(_this) {

		var _msg = $.trim($("#pf_project_textarea").val());
		var _data = {
			"post_temp_id" : iwk_cfg_postform.temp_id,
			"message" : _msg
		};

		// if(iwk_cfg_postform.to.scope == iwk_cfg_postform.const_scope.group){
		// _data.groupid = $("#pf_prj_group_id").val();
		// }

		var _manager = $("#prj_manager_user_picker").userpicker("getData");// $.trim($("#pf_user_id").val());
		if (_manager.number == 0) {
			zebra_alert(iwk_lng.prj_empty_manager);
			return;
		} else {
			_data.manager = _manager.user[0];
		}

		var _name = $.trim($("#pf_project_name").val());
		if (_name !== "") {
			_data.name = _name;
		} else {
			zebra_alert(iwk_lng.prj_empty_name);
			return;
		}

		if (iwk_cfg_postform.attach_sending) {
			zebra_alert(iwk_lng.attach_is_sending_msg);
			return;
		}
		if (iwk_cfg_postform.sending) {
			zebra_alert(iwk_lng.is_sending_msg);
			return;
		}

		var _enddate = $.trim($("#pf_project_enddate").val());
		if (_enddate != "") {
			_data.enddate = _enddate + " 23:59:59";
		} else {
			zebra_alert(iwk_lng.prj_empty_enddate);
			return;
		}
		_data.description = _msg;

		_data.assign_user = new Array();
		var _pk = $("#project_user_picker").userpicker("getData");
		if (_pk.number == 0) {
		} else {
			_data.assign_user = _pk.user;
			_data.assign_group = _pk.group;
			_data.assign_org = _pk.org;
		}

		var _customer = $('#pf_project_customer').pulldown2('getVal');
		if (_customer && _customer.res) {
			_data.customer = _customer.res;
		}

		// 类型
		var _projecttype = $('#pf_project_type').pulldown2('getVal');
		if (_projecttype && _projecttype.res) {
			_data.projecttype = _projecttype.res;
		}

		var _amount = $.trim($("#pf_project_amount").val());
		if (_amount != "") {
			_data.amount = _amount;
		}

		var _startdate = $.trim($("#pf_project_startdate").val());
		if (_startdate != "") {
			_data.startdate = _startdate + " 00:00:00";
		}

		if (iwk_cfg_postform.post_id != 0) {
			var id = iwk_cfg_postform.post_id.split("_");
			if (id != null && $(id).size() > 1 && id[1] > 0) {
				_data.editpost = iwk_cfg_postform.post_id;
			}
		}

		var _url = document.URL;
		iwk_cfg_postform.sending = 1;
		$.post('' + 'apps/project/ajax/formsubmit/ajaxtp:xml/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			iwk_cfg_postform.sending = 0;
			var _st = res.info;
			if (_st.state == "OK") {
				window.location.href = _url;
			} else {
				zebra_alert(res.info.msg);
			}
		}, 'json');
	},
	init_form_data : function() {
		$("#pf_user_id").val("");
		$("#pf_project_textarea").val("");
		$("#pf_project_name").val("");
		$("#pf_customer_id").val("");
		$("#pf_project_amount").val("");
		$("#pf_project_startdate").val("");
		$("#pf_project_enddate").val("");
		// $("#pf_sel_manager").find("span").text(iwk_lng.prj_tip_user);
		// $("#pf_sel_customer").find(".pull_down_ttl").text(iwk_lng.prj_tip_customer);

		$('#prj_manager_user_picker').html("");
		$("#prj_manager_user_picker").userpicker({
			placeholder : "+ 添加项目负责人",
			hint : "请输入搜索过滤",
			multi : false,
			withSpecialGroup : iwk_cfg.is_show_special_group,
			defaultUser : [ {
				data : iwk_cfg.my_id,
				name : iwk_cfg.my_name
			} ]
		});

		$('#project_user_picker').html("");
		$("#project_user_picker").userpicker({
			placeholder : "+ 添加项目组成员",
			hint : "请输入搜索过滤",
			withSpecialGroup : iwk_cfg.is_show_special_group,
			defaultUser : [ {
				data : iwk_cfg.my_id,
				name : iwk_cfg.my_name
			} ]
		});

		iwk_cfg_postform.temp_at_file = 0;
		iwk_cfg_postform.post_id = 0;

		iwk_project.close_windows();
		// iwk_post.synchronize();
	},
	// 弹出子任务新增界面
	show_new_child_task : function(_tid, _ttx) {
		$.fancybox({
			'modal' : true,
			'scrolling' : 'no',
			'href' : '#iwk_postform_task',
			'helpers' : {
				overlay : {
					opacity : 0.2
				}
			},
			'beforeLoad' : function() {
				$("#pf_parent_task_id").val(_tid);
				$("#parent_title").find("label").html(_ttx);
				$("#pf_task_cancel").show();
				$("#iwk_send_child_task").show();
			},
			'afterShow' : function() {
			}
		});
	},
	close_windows : function() {
		$.fancybox.close();
	},
	report_show_task : function(_this, _index) {
		var _tabs = $("a[name=proecess]").parent();
		var _tab_divs = $("div[name=proecess_div]");
		var _tab;
		var _t_div;
		for ( var i = 0; i < _tabs.length; i++) {
			_tab = _tabs[i];
			_t_div = _tab_divs[i];
			$(_tab).removeClass("focus");
			$(_t_div).hide();
			if (i == _index) {
				$(_tab).addClass("focus");
				$(_t_div).show();
			}
		}
	},
	// 弹出项目编辑界面
	show_edit_project : function(_postid) {
		$('#iwk_postfrom_project_body').show();
		$.fancybox({
			'modal' : true,
			'scrolling' : 'visible',
			'href' : '#iwk_project_postform',
			'helpers' : {
				overlay : {
					opacity : 0.2
				}
			},
			'beforeLoad' : function() {
				$("#prj_form_cancel").show();
				_postid = "public_" + _postid;
				iwk_project.edit(_postid, function(res) {
					if (res.status.toLowerCase() == "ok") {
						iwk_cfg_postform.post_id = 'public_' + _postid;
						iwk_project.project_load(res);
					} else {
						zebra_alert(res.message);
						iwk_project.init_form_data();
					}
				});
			},
			'afterShow' : function() {
				$("#cancel_edit_project").show();
			},
			'afterClose' : function() {
				iwk_project.init_edit_window_data();
			}
		});
	},

	init_edit_window_data : function() {
		// $("#iwk_postform").html("");
		var edit_div = $("#iwk_project_postform").html();
		$("#iwk_postform").append(edit_div);
		iwk_project.init_form_data();
		iwk_cfg_postform.sending = 0;
		$("#cancel_edit_project").hide();
	},

	// 取消编辑
	cancel_edit : function() {
		iwk_project.init_form_data();
		$.fancybox.close();
	},

	// 编辑加载数据
	project_load : function(res) {
		var data = res.post;
		var _id = data.id;
		var _message = data.message;
		var _description = data.description;
		var _groupname = data.groupname;
		var _groupid = data.groupid;
		var _name = data.name;
		var _startdate = iwk_common.get_date(data.startdate);
		var _enddate = iwk_common.get_date(data.enddate);
		var _cus_name = data.customer != null ? data.customer.customer_name
				: '';
		var _projecttype = data.projecttype != null ? data.projecttype.name
				: '';
		var _projecttype_id = 0;

		if (_cus_name == 0) {
			_cus_name = '请选择';
		}
		if (data.projecttype) {
			_projecttype_id = data.projecttype.id;
		}

		var _cus_id = data.customer != null ? data.customer.post_id : '';
		var _amount = data.amount;
		var _members = data.users;
		var _manager = data.manager;
		var _m_id = data.manager.id;
		var _m_fname = data.manager.fullname;

		iwk_cfg_postform.to.type = iwk_cfg_postform.const_type.project;
		if (_groupid == 0) {
			$("#postform_group_handler > span").html(
					iwk_lng.postform_init_group);
			iwk_cfg_postform.to.scope = iwk_cfg_postform.const_scope.all;
		} else {
			$("#postform_group_handler > span").html(_groupname);
			iwk_cfg_postform.to.scope = iwk_cfg_postform.const_scope.group;
		}
		iwk_cfg_postform.to.id = _groupid;
		iwk_cfg_postform.post_id = _id;

		$("#pf_user_id").val(_manager.id);
		$("#pf_project_name").val(_name);
		$("#pf_sel_manager").find("span").html(_manager.name);
		$("#pf_project_startdate").val(_startdate);
		$("#pf_project_enddate").val(_enddate);

		if (_cus_id != null && _cus_id != "") {
			$('#pf_project_customer').pulldown2('setVal', {
				ttl : _cus_name,
				res : _cus_id
			});
		}
		if (_projecttype != undefined && _projecttype != '') {
			$('#pf_project_type').pulldown2('setVal', {
				ttl : _projecttype,
				res : _projecttype_id
			})
		}

		$(".customer_kh_class").val(_cus_id);
		$("#pf_project_amount").val(_amount);

		$('#prj_manager_user_picker').html("");
		$("#prj_manager_user_picker").userpicker({
			placeholder : "+ 添加项目负责人",
			hint : "请输入搜索过滤",
			multi : false,
			withSpecialGroup : iwk_cfg.is_show_special_group,
			defaultUser : [ {
				data : _m_id,
				name : _m_fname
			} ]
		});

		$('#project_user_picker').html("");
		if (res.post.array_user == null) {
			$("#project_user_picker").userpicker({
				placeholder : "+ 添加项目组成员",
				hint : "请输入搜索过滤"
			});

		} else {

			$('#project_user_picker').userpicker({
				placeholder : "+ 添加项目组成员",
				hint : "请输入搜索过滤",
				showGroup : false,
				defaultUser : res.post.array_user
			});

		}

		if (_cus_id != "" || _amount != "" || _description != "") {
			$("#prj_show_more").show();
		}

		$("#pf_project_textarea").val(_description);
		iwk_postform.postform_attach_load(res);
	},
	// 项目状态更新
	project_proc : function(posttmpid, type) {
		var _data = {
			"postid" : posttmpid
		};
		_data.type = type;
		$.post('' + 'apps/project/ajax/update/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			if (res.status.toLowerCase() == 'ok') {
				zebra_auto('操作成功', 1000);
				iwk_post.morer_start_from = 10;
				iwk_post.synchronize();
			} else {
				zebra_alert(res.message);
			}
		}, 'json');

	},
	task_state_check : function(obj, key) {
		var _val = $(obj).attr('data');
		var _txt = $(obj).text();
		var _cus = $('.tas_executor').val();
		var _sta = $('.tas_state').val();
		var _class = $(obj).closest(".widget_varsel_wrap").prev().attr("date"); // $(obj).parents('ul').attr('date');
		var _tmp = $(obj).parents('.project_task_block').find('.' + _class)
				.val();
		var _url = '' + 'apps/project/tasks';
		var _puid = $('.project_task_block').attr('rel_data');
		var _array = new Array;
		$(obj).closest(".pull_down").prev("span").text(_txt);
		if (_val == _tmp && _val != undefined) {
			return false;
		} else {
			if (_class == 'tas_state') {
				_sta = _val;
			} else {
				_cus = _val;
			}

			_array = _puid.split('_');
			_url = _url + '/pid:' + _array[0] + '/url:' + _array[1] + '/key:'
					+ key + '/custor:' + _cus + '/state:' + _sta;
			window.location.href = _url;
		}
	}

};

var iwk_priv = {

	send_privmsg : function() {
		var _id = iwk_cfg_postform.to.id;
		var _msg = $.trim($("#pf_post_textarea").val());
		var _data = {
			"post_temp_id" : iwk_cfg_postform.temp_id,
			"message" : _msg
		};

		// if (!_id) {
		// zebra_alert(iwk_lng.post_empty_user);
		// return;
		// }
		if (_msg == "") {
			zebra_alert(iwk_lng.priv_empty_message);
			return;
		}
		if (iwk_cfg_postform.attach_sending) {
			zebra_alert(iwk_lng.attach_is_sending_msg);
			return;
		}
		if (iwk_cfg_postform.sending) {
			zebra_alert(iwk_lng.is_sending_msg);
			return;
		}

		_link_id = $("#priv_link_id").val();
		if (_link_id != null && _link_id != "") {
			_data.link_id = _link_id;
		}
		var _is_multi = $("#priv_is_multi_prv").val();

		// _data.userid = iwk_cfg_postform.to.id;
		// 私信收信人
		var _pk = $("#priv_user").userpicker("getData");
		if (_pk.number == 0) {

			var _user_nums = 0;
			$(".priv_user").each(function() {
				_user_nums += 1;
			});
			if (_user_nums <= 2 && _is_multi == 0) {
				// 单人：发老的单人信息
				_data.userid = iwk_cfg_postform.to.id;
			} else {
				// 多人：
				if (_link_id == null || _link_id == "") {
					zebra_alert(iwk_lng.priv_assign_empty);
					return;
				}
			}
		} else {
			_data.assign_user = _pk.user;
			_data.assign_group = _pk.group;
			_data.assign_org = _pk.org;
		}

		var _title = $("#pf_prv_title").val();
		if (_title != null && _title != "") {
			_data.title = _title;
		}

		iwk_cfg_postform.sending = 1;
		$.post('' + 'apps/priv/ajax/private_submit/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			var _st = res.status.toLowerCase();
			if (_st == "ok") {
				iwk_priv.init_priv_data();
			} else {
				zebra_alert(res.message);
				iwk_cfg_postform.sending = 0;
			}
		}, 'json');
	},

	send_priv_media : function() {
		var _id = iwk_cfg_postform.to.id;
		var _msg = "[附件]";
		var _data = {
			"post_temp_id" : iwk_cfg_postform.temp_id,
			"message" : _msg
		};

		if (_msg == "") {
			fancylay.unblock();
			zebra_alert(iwk_lng.priv_empty_message);
			return;
		}
		if (iwk_cfg_postform.attach_sending) {
			fancylay.unblock();
			zebra_alert(iwk_lng.attach_is_sending_msg);
			return;
		}
		if (iwk_cfg_postform.sending) {
			fancylay.unblock();
			zebra_alert(iwk_lng.is_sending_msg);
			return;
		}

		_link_id = $("#priv_link_id").val();
		if (_link_id != null && _link_id != "") {
			_data.link_id = _link_id;
		}
		var _is_multi = $("#priv_is_multi_prv").val();

		// 私信收信人
		var _pk = $("#priv_user").userpicker("getData");
		if (_pk.number == 0) {

			var _user_nums = 0;
			$(".priv_user").each(function() {
				_user_nums += 1;
			});
			if (_user_nums <= 2 && _is_multi == 0) {
				// 单人：发老的单人信息
				_data.userid = iwk_cfg_postform.to.id;
			} else {
				// 多人：
				if (_link_id == null || _link_id == "") {
					fancylay.unblock();
					zebra_alert(iwk_lng.priv_assign_empty);
					return;
				}
			}
		} else {
			_data.assign_user = _pk.user;
			_data.assign_group = _pk.group;
			_data.assign_org = _pk.org;
		}

		var _title = $("#pf_prv_title").val();
		if (_title != null && _title != "") {
			_data.title = _title;
		}

		// iwk_cfg_postform.sending = 1;
		$.post('' + 'apps/priv/ajax/private_submit/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			var _st = res.status.toLowerCase();
			fancylay.unblock();
			if (_st == "ok") {
				iwk_cfg_postform.temp_id = iwk_common.get_new_guid();
				iwk_cfg_postform.sending = 0;
				iwk_cfg_postform.attach_sending = 0;
				iwk_cfg_postform.removed_attaches.length = 0;

				$('#postform_attach_queue').empty();
				reload_uploadifier();

				iwk_post.synchronize();
			} else {
				zebra_alert(res.message);
				iwk_cfg_postform.sending = 0;
			}
		}, 'json');
	},

	// 发私信完成，初始化数据，并异步调用列表
	init_priv_data : function() {
		iwk_cfg_postform.temp_id = iwk_common.get_new_guid();
		iwk_cfg_postform.sending = 0;
		iwk_cfg_postform.attach_sending = 0;
		iwk_cfg_postform.removed_attaches.length = 0;

		$("#pf_post_textarea").val("");
		$('#postform_attach_queue').empty();
		$("#pf_prv_title").val("");
		reload_uploadifier();

		iwk_post.synchronize();
	},

	// 播放音频
	play_audio : function(url, _this, e) {
		var _sw = $(_this).hasClass('off');
		var _obj = '';
		if (_sw) {
			$(_this).removeClass('off');
		} else {
			$(_this).addClass('off');
			var _pin = ''
					+ 'themes/art/flash/singlemp3player.swf?file='
					+ url
					+ '&autoStart=true&backColor=000000&frontColor=ffffff&songVolume=80';
			var _p1 = '<param name="movie" value="' + _pin + '" />';
			var _p2 = '<param name="wmode" value="transparent" />';
			var _p3 = '<embed wmode="transparent" width="1" height="1" src="'
					+ _pin
					+ '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
			_obj = $('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="0" height="0" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
					+ _p1 + _p2 + _p3 + '</object>');
		}
		$("#bgmusic").html(_obj);

		if (e) {
			iwk_common.stop_propagation(e);
		}
	},

	// 退出会话
	exit_talk : function(_this, _user_id) {
		var _url = document.URL;
		var _link_id = $("#priv_link_id").val();
		zebra_confirm(iwk_lng.priv_exit_talk, function() {
			$.fancybox.close();

			if (_link_id == null || _link_id == '') {
				zebra_alert(iwk_lng.priv_exit_error_link);
				return;
			}
			var _data = {
				"action" : "exit",
				"userid" : _user_id,
				"linkid" : _link_id
			};
			$.post('' + 'apps/priv/ajax/prv_update/r:'
					+ Math.round(Math.random() * 1000), _data, function(res) {
				var _st = res.status.toLowerCase();
				if (_st == "ok") {
					if (iwk_cfg.my_id != _user_id) {
						$.fancybox.close();
						$(_this).closest(".irbb_line").remove();
						iwk_post.synchronize();
					} else {
						window.location.href = '' + "apps/priv";
					}
				} else {
					zebra_alert(res.message);
				}
			}, 'json');
		});
	},

	show_add_user : function() {

		$.fancybox({
			'modal' : true,
			'scrolling' : 'auto',
			'href' : '#postform_priv_add_user',
			'helpers' : {
				overlay : {
					opacity : 0.2
				}
			},
			'beforeLoad' : function() {
				var _filter = new Array();
				var _row = 0;
				$(".prv_group_user").each(function() {
					var _id = $(this).attr("data")
					_filter[_row] = _id;
					_row++;
				});
				$("#priv_show_add_users").userpicker("reload", {
					filterUser : _filter
				});
			}
		});

	},

	append_user_ok : function() {
		var _data = {
			"action" : "append"
		};
		var _pk = $("#priv_show_add_users").userpicker("getData");
		if (_pk.number == 0) {
			zebra_alert("请选择用户!");
		} else {
			$.fancybox.close();

			_data.assign_user = _pk.user;
			_data.assign_group = _pk.group;
			_data.assign_org = _pk.org;

			_link_id = $("#priv_link_id").val();
			if (_link_id != null && _link_id != "") {
				_data.link_id = _link_id;
			}

			var _creator_user = $("#prv_group_creator").val();
			var _user_nums = 0;
			$(".priv_user").each(function() {
				_user_nums += 1;
			});

			var _is_multi = $("#priv_is_multi_prv").val();
			if (_is_multi == 1) {
				_data.is_multi = _is_multi;
			} else {
				_is_multi = 0;
			}

			var _is_add = false;
			// var total_users = _pk.number + _user_nums;
			if (_user_nums <= 2 && _is_multi == 0) {
				zebra_confirm("单人私信成员变化将开启一条新的会话，确定开启吗？", function() {
					// 阻塞
					fancylay.block();
					$.post('' + 'apps/priv/ajax/prv_update/r:'
							+ Math.round(Math.random() * 1000), _data,
							function(res) {
								if (res.status.toLowerCase() == 'ok') {
									if (res.linkid) {
										$("#priv_link_id").val(res.linkid);
										window.location.href = ''
												+ "apps/priv/view/link:"
												+ res.linkid;
									}
								}
								fancylay.unblock();
								$.fancybox.close();
								zebra_alert(res.message);
							}, 'json');
				});
			} else {
				// 阻塞
				fancylay.block();
				$
						.post(
								''
										+ 'apps/priv/ajax/prv_update/r:'
										+ Math.round(Math.random() * 1000),
								_data,
								function(res) {
									if (res.status.toLowerCase() == 'ok') {
										if (res.data) {
											for ( var i = 0; i < res.data.length; i++) {
												var _div = "";
												if (iwk_cfg.my_id == _creator_user
														&& _creator_user != ""
														&& _creator_user > 0) {
													// 群聊创建人
													_div = '<div class="irbb_line priv_user" style="height:32px;">'
															+ '<a href="'
															+ (''
																	+ 'inside/user/url:' + res.data[i].id)
															+ '" title="'
															+ res.data[i].fullname
															+ '" style="width:32px;height:32px;float:left;">'
															+ '<img src="'
															+ res.avatars[i]
															+ '" alt="'
															+ res.data[i].fullname
															+ '" width="32px" height="32px">'
															+ '</a>'
															+ '<div style="float:left;padding-left:6px;" class="prv_group_user" data="'
															+ res.data[i].id
															+ '"> '
															+ res.data[i].fullname
															+ ' </div>'
															+ '<div class="fr"><a href="javascript:;" style="clear:both;width:60px;" onclick="iwk_priv.exit_talk(this,\''
															+ res.data[i].id
															+ '\')">[退出会话]</a></div>'
															+ '</div>';
												} else {
													_div = '<div class="irbb_line priv_user" style="height:32px;">'
															+ '<a href="'
															+ (''
																	+ 'inside/user/url:' + res.data[i].id)
															+ '" title="'
															+ res.data[i].fullname
															+ '" style="width:32px;height:32px;float:left;">'
															+ '<img src="'
															+ res.avatars[i]
															+ '" alt="'
															+ res.data[i].fullname
															+ '" width="32px" height="32px">'
															+ '</a>'
															+ '<div style="float:left;padding-left:6px;" class="prv_group_user" data="'
															+ res.data[i].id
															+ '"> '
															+ res.data[i].fullname
															+ ' </div>'
															+ '</div>';
												}

												$("#prv_group_user_list")
														.append(_div);
											}

											iwk_post.synchronize();
										}
									}
									fancylay.unblock();
									$.fancybox.close();
									zebra_alert(res.message, function() {
										$.fancybox.close();
									});
								}, 'json');
			}
		}
	},

	refresh_prv_data : function() {
		// modified by Erich Lee
		// var _url =
		// document.URL+"/from:ajax/r:"+Math.round(Math.random()*1000);
		// $.post(_url, function(res){
		iwk_post.synchronize(function() {
			setTimeout(iwk_priv.refresh_prv_data, 5000);
		}, false);
		// });
	}

};

var iwk_vote = {
	add_input : function() {
		var abc = Array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
				'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
				'X', 'Y', 'Z');

		var _elel = $('#input_list_id :input');

		var ea = _elel.length;
		// var n=_elel.length+1;
		if (_elel.length > 19) {
			zebra_alert(iwk_lng.vote_ele_num);
			return false;
		}
		var st = '<div class="vote_input_div"><span class="vote_input"><span class="span_vote_xx">'
				+ iwk_lng.vote_ele_xx
				+ '<span>'
				+ abc[ea]
				+ '</span>:</span><span><input name="ele[]" class="ele_val" type="text"  /></span></span><a style="display:none" href="javascript:void(0)" class="span_vote_del" title="删除" onclick="iwk_vote.del_input(this);"></a></div>';
		$('#input_list_id').append(st);

		if ($('#input_list_id :input').length > 2) {
			$('#input_list_id .span_vote_del').show();
		}
	},

	del_input : function(obj) {
		var abc = Array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
				'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
				'X', 'Y', 'Z');

		var _elel = $('#input_list_id :input');

		var _an_el = $('#input_list_id').find('.span_vote_xx');

		var abc_len = _elel.length;

		if (_elel.length < 3) {
			return false;
		}

		for ( var ae = 0; ae < abc_len; ae++) {

			if ($(obj).parents('.vote_input_div').find('.span_vote_xx').find(
					'span').text() == $(_an_el[ae]).find('span').text()) {

				var gg = ae;

			}
		}

		$(obj).parents('.vote_input_div').remove();

		for ( var ac = gg; ac < abc_len - 1; ac++) {
			$(_an_el[ac + 1]).find('span').text(abc[ac]);
		}

		if ($('#input_list_id :input').length < 3) {
			$('#input_list_id .span_vote_del').hide();
		}
	},

	save : function(post_id, callback) {
		var url = '' + 'ajax/vote_data/action:vote';
		var _input_a = $("input[name='vote_option_" + post_id + "']");
		var _input_v = new Array();
		var en = 0;
		for ( var i = 0; i < _input_a.length; i++) {
			if (_input_a[i].checked == true) {
				_input_v[en] = $(_input_a[i]).attr("data");
				en++;
			}
		}
		if (_input_v.length == 0) {
			zebra_alert(iwk_lng.vote_input_num);
			return false;
		}
		var _input_vs = _input_v.join('|@|');
		var _data = {
			postid : post_id,
			input_vs : _input_vs
		};
		$.post(url, _data, function(res) {
			rn = eval('(' + res + ')');
			if (rn._status == 'error') {
				zebra_alert(rn.msg);
				return false;
			} else {
				callback(post_id);
			}
		});
	},

	ajax_vote : function(post_id) {
		iwk_vote.save(post_id, function(post_id) {
			zebra_alert('投票成功!');
			var pid = 'public_' + post_id;
			iwk_post.synchronize_single(pid);
		});
	},

	ajax_vote_v : function(post_id) {
		iwk_vote.save(post_id, function(post_id) {
			view_refresh_callback('投票成功');
		});
	},

	ajax_status : function(post_id) {
		var url = '' + 'ajax/vote_data/action:status';
		url = url + "/postid:" + post_id + "/s:" + Math.random();
		$.get(url, function(res) {
			rn = eval('(' + res + ')');
			if (rn.status == 0) {
				zebra_alert(rn.msg);
				return false;
			} else {
				// zebra_alert('发布成功');
				var pid = 'public_' + post_id;
				iwk_post.synchronize_single(pid);
			}
		});
	},

	del : function(post_id, callback_after, callback_onclose) {
		zebra_confirm(iwk_lng.vote_del_confirm, function() {
			$.post('' + 'ajax/vote_data/action:del/postid:'
					+ post_id + '/r:' + Math.round(Math.random() * 1000),
					function(res) {
						if (callback_after)
							callback_after(res);
					});
		}, null, callback_onclose);
	},

	ajax_del : function(post_id) {
		var _err_info = '';

		iwk_vote.del(post_id, function(res) {
			rn = eval('(' + res + ')');
			if (rn._status == 'error') {
				_err_info = rn.msg;
			} else {
				$("#sp_public_" + post_id).slideUp('slow', function() {
					$(_this).remove();
				});
			}
		}, function() {
			if (_err_info) {
				zebra_alert(_err_info);
			}
		});
	},

	ajax_del_v : function(post_id) {
		var _is_deleted = false;

		iwk_vote.del(post_id, function() {
			$("#view_wrap").empty().html(
					'<div style="padding:10px 0;"><a href="' + ''
							+ '">返回首页</a></div>');
			_is_deleted = true;
		}, function() {
			if (_is_deleted) {
				zebra_alert("删除成功!");
			}
		});
	},

	click_rad_che : function(obj) {
		var ty = $(obj).attr('type');
		var cl = $(obj).attr('class');
		if (ty == 'radio') {
			$('.' + cl).parent('span').removeClass('checked');
			$('.' + cl).removeAttr('checked');
			$(obj).parent('span').addClass('checked');
			$(obj).attr('checked', 'checked');
		} else {

			if ($(obj).parent('span').attr('class') == 'checked') {
				$(obj).parent('span').removeClass('checked');
				$(obj).removeAttr('checked');
			} else {
				$(obj).parent('span').addClass('checked');
				$(obj).attr('checked', 'checked');
			}
		}
	},

	hide_detail : function(_this, post_id) {
		var _parent = $("#sp_" + post_id);
		_parent.find(".iwk_single_vs_wrap").hide();
	},

	show_detail : function(_this, post_id) {
		var _parent = $("#sp_" + post_id);
		_parent.find(".comments").hide();
		if (iwk_cfg.is_ie) {
			_parent.find(".iwk_single_vs_wrap").toggle();
		} else {
			_parent.find(".iwk_single_vs_wrap").slideToggle();
		}
	}
};

var iwk_survey = {
	add_html : function() {
		var _url = ''
				+ 'ajax/survey_data/type:all/action:add_html';
		$.get(_url, function(res) {
			if (res._status == 'ok') {
				var _o = $(res.html);
				$('#postform_body_survey .survey_list_wrap').show();
				$('#postform_body_survey .survey_list_wrap').append(_o);

				_o.find('.class_type').pulldown({
					title : '客观题',
					mode : 1,
					fixed_options : [ {
						ttl : '客观题',
						res : 1
					}, {
						ttl : '主观题',
						res : 2
					} ],
					event : function(self) {
						iwk_survey.class_select(self);
					}
				});

				_o.find('.type').pulldown({
					title : '单选',
					mode : 1,
					fixed_options : [ {
						ttl : '单选',
						res : 1
					}, {
						ttl : '多选',
						res : 2
					} ]
				});
			}
		}, 'json');
	},

	attr : function() {
		var _url = '' + 'ajax/survey_data/type:all/action:attr';
		var _pid = $('#sur_post_id').val();
		var _pkey = $('#sur_pkey_id').val();

		if (_pid == 0 || _pkey == 0 || _pid == '') {
			return false;
		}

		var _data = {
			p_id : _pid,
			p_key : _pkey
		};

		$.post(_url, _data, function(res) {
			rn = eval('(' + res + ')');
			if (rn._status == 'ok') {
				iwk_cfg_postform.post_id = 'public_' + _pid;
				// iwk_postform.postform_attach_load(rn.rse);
				// iwk_postform.append_attach_to_view(_type,
				// iwk_cfg_postform.temp_data.filename, '', _id);
				$.each(rn.rse.attaches, function(i, n) {
					// alert(n.id);return false;

					var _id = n.id;
					var _type = n.type;
					var _filename = n.filename;
					var keyy = iwk_common.get_new_guid();
					iwk_cfg_postform.temp_data = {
						keyy : keyy,
						filename : _filename
					};
					iwk_postform.append_attach_to_view(_type,
							iwk_cfg_postform.temp_data.filename, '', _id);
				});
			} else {

			}
		});
	},

	add_dd : function(obj) {
		var abc = Array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
				'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
				'X', 'Y', 'Z');

		var _elel = $(obj).parent().prev('.survey_options').children(
				'.sur_input');
		var abc_len = _elel.length;

		var sop = '<div class="sur_input">';
		sop = sop + '<span class="si_all">';
		sop = sop + '<span class="s_xx">选项</span>';
		sop = sop + '<span class="s_zm">' + abc[abc_len] + '</span>';
		sop = sop
				+ '<span class="s_in">:<input type="text" name="opt[]" class="opt" /></span>';
		sop = sop + '</span>';
		sop = sop
				+ '<a href="javascript:void(0)" class="si_del" onclick="iwk_survey.del_dd(this)"></a>';
		sop = sop + '</div>';

		if (abc_len > 24) {
			// zebra_alert('选项不能超过 25个!')
			return false;

		}

		$(obj).parent().prev('.survey_options').append(sop);

		if ($(obj).parent().prev('.survey_options').children('.sur_input').length > 1) {
			$(obj).parent().prev('.survey_options').find('.si_del').show();
		}
	},

	del_dd : function(obj) {
		var abc = Array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
				'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
				'X', 'Y', 'Z');
		var _elel = $(obj).parents('.survey_options').find('.sur_input');
		var abc_len = _elel.length;

		if (_elel.length < 4) {
			$(obj).parents('.survey_options').find('.si_del').hide();
		}

		if (_elel.length < 3) {
			return false;
		}

		for ( var ae = 0; ae < abc_len; ae++) {
			// if($(obj).parent()[0].firstElementChild.innerHTML==$(_elel[ae]).find('span')){
			if ($(obj).parents('.sur_input').find('.s_zm').text() == $(
					_elel[ae]).find('.s_zm').text()) {
				var gg = ae;
			}
		}

		$(obj).parents('.sur_input').remove();

		for ( var ac = gg; ac < abc_len - 1; ac++) {
			$(_elel[ac + 1]).find('.s_zm').text(abc[ac]);
		}
	},

	del_list : function(obj) {
		zebra_confirm('你确定要删除此问题?', function() {
			$(obj).parents('.survey_list').slideUp(600, function() {
				$(obj).parents('.survey_list').remove();
			});
		});
	},

	class_select : function(obj) {
		if (obj.attr("data") == 2) {
			obj.closest('.survey_list').find('.su_t_span_op').hide();
			obj.closest('.survey_list').find('.su_t_span_other').hide();
			obj.closest('.survey_list').find('.survey_options').hide();
			obj.closest('.survey_list').find('.survey_button').hide();
		} else {
			obj.closest('.survey_list').find('.su_t_span_op').show();
			obj.closest('.survey_list').find('.su_t_span_other').show();
			obj.closest('.survey_list').find('.survey_options').show();
			obj.closest('.survey_list').find('.survey_button').show();
		}
	},

	single_multi_select : function(obj) {
		$(obj).parents('.iwk_pulldown_link').find('span').text($(obj).text());
		$(obj).parents('.iwk_pulldown_link').find('.type').val(
				$(obj).attr('data'));
	},

	del : function(post_id, callback_after, callback_onclose) {
		zebra_confirm(iwk_lng.vote_del_confirm, function() {
			$.post('' + 'ajax/survey_data/action:del/postid:'
					+ post_id + '/r:' + Math.round(Math.random() * 1000),
					function(res) {
						if (callback_after)
							callback_after(res);
					});
		}, null, callback_onclose);
	},

	del_survey : function(post_id) {
		iwk_survey.del(post_id, function(res) {
			var _err_info = '';
			rn = eval('(' + res + ')');

			if (rn._status == 'error') {
				_err_info = rn.msg;
			} else {
				$("#sp_public_" + post_id).slideUp('slow', function() {
					$(this).remove();
				});
			}
			if (_err_info !== '') {
				zebra_alert(_err_info);
			}
		});
	},

	del_survey_v : function(post_id) {
		var _is_deleted = false;

		iwk_survey.del(post_id, function() {
			$("#view_wrap").empty().html(
					'<div style="padding:10px 0;"><a href="' + ''
							+ '">返回首页</a></div>');
			_is_deleted = true;
		}, function() {
			if (_is_deleted) {
				zebra_alert("删除成功!");
			}
		});
	},

	sub_other : function(obj) {
		if ($(obj).text() == '查看其它值') {
			$(obj).parents('.su_title').find('ul').show();
			$(obj).text('收起其它值');
		} else {
			$(obj).parents('.su_title').find('ul').hide();
			$(obj).text('查看其它值');
		}
	},

	save : function(obj, callback) {
		var _url = '' + 'ajax/survey_data/action:status';
		var dl = $(obj).closest('.iwk_single_vs_wrap').find('.isvw_wrap');
		var v_data = new Array();
		var dl_len = dl.length;
		var p_ssid = $(obj).attr('data');

		for ( var i = 0; i < dl_len; i++) {
			v_data[i] = {};
			v_data[i]['title_id'] = $(dl[i]).attr('data');
			v_data[i]['class_type'] = $(dl[i]).attr('class_type');
			var v_len = $(dl[i]).find('.survey_option_box').length;
			v_data[i]['l_data'] = {};
			var m = 0;

			if (v_data[i]['class_type'] == 2) {

				v_data[i]['l_text'] = {};
				v_data[i]['l_text']['id'] = $($(dl[i]).find('.widget_ipt_lite'))
						.attr('data');
				v_data[i]['l_text']['text'] = $(
						$(dl[i]).find('.widget_ipt_lite')).val();

				if (v_data[i]['l_text']['text'] == '') {
					zebra_alert('请回答问答题!');
					return false;
				}
			} else {

				for ( var n = 0; n < v_len; n++) {
					if ($($(dl[i]).find('.survey_option_box')[n]).attr(
							'checked') == 'checked') {
						if ($($(dl[i]).find('.survey_option_box')[n]).attr(
								'class_type') == 1) {
							v_data[i]['l_text'] = {};
							v_data[i]['l_text']['id'] = $(
									$(dl[i]).find('.survey_option_box')[n])
									.attr("data");
							v_data[i]['l_text']['text'] = $(
									$(dl[i]).find('.widget_ipt_lite')).val();

							if (v_data[i]['l_text']['text'] == '') {
								zebra_alert('请输入 其它选项值!');
								return false;
							}
						} else {
							v_data[i]['l_data'][m] = $(
									$(dl[i]).find('.survey_option_box')[n])
									.attr("data");
							m++;
						}
					}
				}
			}
		}

		var _data = {
			p_data : v_data,
			p_ssid : p_ssid
		};

		$.post(_url, _data, function(res) {
			rn = eval('(' + res + ')');
			if (rn._status == 'ok') {
				callback(p_ssid);
			} else {
				zebra_alert(rn.msg);
			}
		});
	},

	sub_value : function(obj) {
		iwk_survey.save(obj, function(p_id) {
			var pid = 'public_' + p_id;
			$('#sp_' + pid).slideUp(600);
			iwk_post.synchronize_single(pid);
			zebra_alert('提交成功!');
		});
	},

	sub_value_v : function(obj) {
		iwk_survey.save(obj, function(p_id) {
			view_refresh_callback('提交成功!');
		});
	},

	click_rad_che : function(obj) {
		var ty = $(obj).attr('type');
		var t_v = $(obj).val();

		if (ty == 'radio') {
			$(obj).parents('dl').find('span').removeClass('checked');
			$(obj).parents('dl').find('.y_val').removeAttr('checked');

			$(obj).parent('span').addClass('checked');
			$(obj).attr('checked', 'checked');

			if ($(obj).parents('dl').find('.it_p').html() != null) {
				$(obj).parents('dl').find('.it_p').attr('disabled', "disabled")
			}

			if ($(obj).parents('.d_ys').find('.it_p').html() != null) {
				$(obj).parents('.d_ys').find('.it_p').removeAttr('disabled');
			}

		} else {

			if ($(obj).parent('span').attr('class') == 'checked') {
				$(obj).parent('span').removeClass('checked');
				$(obj).removeAttr('checked');

				if ($(obj).parents('.d_ys').find('.it_p').html() != null) {
					$(obj).parents('.d_ys').find('.it_p').attr('disabled',
							"disabled");
				}

			} else {
				$(obj).parent('span').addClass('checked');
				$(obj).attr('checked', 'checked');

				if ($(obj).parents('.d_ys').find('.it_p').html() != null) {
					$(obj).parents('.d_ys').find('.it_p')
							.removeAttr('disabled');
				}
			}
		}

	},

	get_by_id_result : function(obj) {
		var id = $(obj).attr('rel_id');
		var _url = '' + 'ajax/survey_data/action:ajax_result/rid:'
				+ id;
		$.get(_url, function(res) {
			if (res._status == 'ok') {
				$('#fancy_survey_result').html(res.html);
				$('#fancy_survey_result').attr('width');
				$.fancybox({
					'modal' : false,
					'scrolling' : 'auto',
					'href' : '#fancy_survey_result',
					'helpers' : {
						overlay : {
							opacity : 0.2
						}
					},
					'beforeLoad' : function() {
					}
				});
			} else {
				zebra_alert(res.msg);
			}

		}, 'json');
	},

	click_single_option : function(_this, _type) {
		var _parent = $(_this).closest(".isvw_wrap");
		var _input = $(_this).find("input");
		if (_input.is(":radio")) {
			if (_type == 0) {
				_parent.find(".widget_ipt_lite_wrap").removeClass("disabled")
						.find(".widget_ipt_lite").attr("readonly", false);
			} else {
				_parent.find(".widget_ipt_lite_wrap").addClass("disabled")
						.find(".widget_ipt_lite").attr("readonly", true);
			}
		} else {
			if (_type == 0) {
				var _checked = _input.is(":checked");
				if (_checked) {
					_parent.find(".widget_ipt_lite_wrap").removeClass(
							"disabled").find(".widget_ipt_lite").attr(
							"readonly", false);
				} else {
					_parent.find(".widget_ipt_lite_wrap").addClass("disabled")
							.find(".widget_ipt_lite").attr("readonly", true);
				}
			}
		}
	}
};

var iwk_notice = {
	postform_send_notice : function(s_type) {

		var _url = '' + 'ajax/notice_data';
		var _title = $('#title').val();
		var _content = $.trim(editor.html());
		var _check_type = $('#check_type_id').val();
		var _editor_post_id = $('#post_value_id').val();
		var _post_key = $('#post_key_id').val();

		if (_content == '<br />') {/* chrome */
			_content = '';
		}

		if (iwk_cfg_postform.sending) {
			zebra_alert('公告正在发送中...');
			return false;
		}

		iwk_cfg_postedit.sending = 1;

		if (s_type == 'a') {
			var _state = 0;
		} else {
			var _state = 2;
		}

		var _data = {
			post_temp_id : iwk_cfg_postform.temp_id,
			title : _title,
			status : _state,
			content : _content,
			editor_id : _editor_post_id,
			post_key : _post_key,
			check_type : _check_type
		};

		if (iwk_cfg_postedit.post_id != 0) {
			var id = iwk_cfg_postedit.post_id.split("_");
			if (id != null && $(id).size() > 1 && id[1] > 0) {
				_data.editpost = iwk_cfg_postedit.post_id;
				_data.removed_attaches = iwk_cfg_postedit.removed_attaches
						.join(",");
			}
		}

		if (iwk_cfg_postedit.to.scope == iwk_cfg_postedit.const_scope.group) {
			_data.groupid = iwk_cfg_postedit.to.id;
		} else if (iwk_cfg_postedit.to.scope == iwk_cfg_postedit.const_scope.user) {
			_data.userid = iwk_cfg_postedit.to.id;
		} else if (iwk_cfg_postedit.to.scope == iwk_cfg_postedit.const_scope.all) {
			_data.groupid = 0;
		}

		$.post(_url, _data, function(res) {
			rn = eval('(' + res + ')');
			iwk_cfg_postedit.sending = 0;
			if (rn._status == 'ok') {
				zebra_alert(rn.msg);
				iwk_post.synchronize();
				iwk_notice.reset_n_add();
				$("#iwk_postform_attachs").empty();
				$("#postform_attach_queue").empty();
				$('#notice_add').pulldown2('setVal', {
					ttl : '请选择',
					res : ''
				});

				iwk_notice.init_postedit_cfg();
			} else {
				zebra_alert(rn.msg);
				return false;
			}

		});
	},
	init_postedit_cfg : function() {
		iwk_cfg_postform.temp_id = iwk_common.get_new_guid();
		iwk_cfg_postedit.sending = 0;
		iwk_cfg_postedit.attach_sending = 0;
		iwk_cfg_postedit.removed_attaches.length = 0;
		iwk_cfg_postedit.post_id = 0;
		iwk_cfg_postedit.tag_pos.start = -1;
		iwk_cfg_postedit.tag_pos.end = -1;

		// 初始化附件
		$('#postform_attach_queue').empty();
		// $('#postform_attach_btn').uploadify('cancel', '*');
	},
	checkbox_sub : function(obj) {
		var val = $(obj).attr('data');
		var _txt = $(obj).text();
		$(obj).closest(".pull_down").prev("span").text(_txt);
		$('#check_type_id').val(val);

	},
	audit : function(obj, callback) {
		var _url = '' + 'ajax/notice_data/action:gupdate';
		var _content = $(obj).parent().parent().children()[0].value;
		var _pid = $(obj).attr('data');
		var _status = $('#' + _pid + '_status_id').val();

		var _data = {
			status : _status,
			content : _content,
			pid : _pid
		};
		$.post(_url, _data, function(res) {
			rn = eval('(' + res + ')');
			zebra_auto(rn.msg, 1000);
			if (rn._status == 'error') {
				return false;
			} else {
				callback(_pid);
			}
		});
	},

	update_status : function(obj) {
		$.fancybox.close();
		iwk_notice.audit(obj, function(_pid) {
			iwk_post.synchronize();
		});
	},

	update_status_v : function(obj) {
		iwk_notice.audit(obj, function(_pid) {
			view_refresh_callback('提交成功!');
		});
	},

	update_status_jump : function(obj) {
		$.fancybox.close();
		iwk_notice.audit(obj, function(_pid) {
			location.href = '' + 'inside/view/post:' + _pid;
		});
	},

	del : function(post_id, callback_after, callback_onclose) {
		zebra_confirm(iwk_lng.vote_del_confirm, function() {
			$.post('' + 'ajax/notice_data/action:del/r:'
					+ Math.round(Math.random() * 1000), {
				dpid : post_id
			}, function(res) {
				if (callback_after)
					callback_after(res);
			});
		}, null, callback_onclose);
	},

	notice_delete : function(_this, post_id) {

		zebra_confirm(iwk_lng.vote_del_confirm, function() {
			$.post('' + 'ajax/notice_data/action:del/r:'
					+ Math.round(Math.random() * 1000), {
				dpid : post_id
			}, function(res) {
				rn = eval('(' + res + ')');
				if (rn._status == 'ok') {
					$("#sp_" + post_id).slideUp('slow', function() {
						$("#sp_" + post_id).remove();
					});
				} else {
					zebra_alert(rn.msg);
				}
			});
		});
	},

	notice_delete_v : function(post_id) {
		var _is_deleted = false;

		iwk_notice.del(post_id, function() {
			$("#view_wrap").empty().html(
					'<div style="padding:10px 0;"><a href="' + ''
							+ '">返回首页</a></div>');
			_is_deleted = true;
		}, function() {
			if (_is_deleted) {
				zebra_alert("删除成功!");
			}
		});
	},

	get_notice_by_id : function(_pid) {
		iwk_notice.reset_n_add();

		var _url = '' + 'ajax/notice_data/action:get';
		_url = _url + '/pid:' + _pid + '/r:' + Math.round(Math.random() * 1000);

		$
				.get(
						_url,
						function(res) {
							rn = eval('(' + res + ')');
							if (rn._status == 'error') {
								zebra_alert(rn.msg);
								return false;
							} else {
								var check_user_id = rn.check_user_id != null ? rn.check_user_id
										: 0;
								var check_user_name = rn.check_user_name != null ? rn.check_user_name
										: '请选择';
								if (check_user_id > 0) {
									$("#check_type_id").val(check_user_id)
								}
								;

								$('#notice_add').pulldown2('setVal', {
									ttl : check_user_name,
									res : check_user_id
								});
								$('#title').val(rn.message);
								$('#post_value_id').val('public_' + rn.pid);
								$('#post_key_id').val(rn.key_value);
								$('#reset_mod_sender_id').show();

								$('#title').focus();

								iwk_cfg_postedit.post_id = _pid;
								// iwk_notice.attr(rn.pid);

								if (rn._status == 'ok') {
									$('#mod_check_id').show();
								}
								editor.html(rn.content);

								iwk_notice.get_attr(_pid);

							}
						});
	},
	get_attr : function(_pid) {
		var _url = '' + 'ajax/notice_data/action:attr';
		_url = _url + '/pid:' + _pid + '/r:' + Math.round(Math.random() * 1000);

		iwk_cfg_postedit.post_id = _pid;

		$.get(_url, function(rn) {
			rn = jQuery.parseJSON(rn);
			if (rn.attr_status == 1) {
				var attach = rn.attr;
				if (typeof (attach) == "undefined" || attach == "") {
					return;
				}
				$("#postform_attach_queue").empty();
				$.each(attach, function(i, n) {
					var _id = n.id;
					var _type = n.type;
					var _filename = n.file_name + "." + n.file_type;
					iwk_notice.append_attach_to_view(_id, _filename);
				});

				// $.each(rn.attaches, function(i, n) {
				// //alert(n.id);return false;
				//					
				// var _id = n.id;
				// var _type = n.type;
				// var _filename = n.filename;
				// var keyy = iwk_common.get_new_guid();
				// iwk_cfg_postedit.temp_data = {keyy:keyy, filename:_filename};
				// iwk_postform.append_attach_to_view(_type,
				// iwk_cfg_postedit.temp_data.filename, '', _id);
				// });

			}
		});
	},

	append_attach_to_view : function(id, filename) {
		var _str = '<div id="edit_attach_'
				+ id
				+ '" class="uploadify-queue-item">'
				+ '<div class="cancel">'
				+ '<a data="'
				+ id
				+ '" onclick="iwk_postedit.set_removed_attach(this)" href="javascript:;">删除</a>'
				+ '</div>' + '<span class="fileName">' + filename + '</span>'
				+ '</div>';
		$(_str).appendTo("#postform_attach_queue");
	},

	postform_reset : function() {
		iwk_notice.reset_n_add();
	},
	get_notice_check_content : function(obj) {
		var _editor_post_id = $('#post_value_id').val();
		var _post_key = $('#post_key_id').val();
		var _url = '' + 'ajax/notice_data/action:check';
		var _data = {
			editor_post_id : _editor_post_id,
			editor_post_key : _post_key
		};
		var _res_data = $('.notice_check').html();
		var _tx = $(obj).html();
		if (_tx == '收起原因') {
			$('.notice_check').remove();
			$(obj).html('查看未通过原因');
			return;
		}

		$.post(_url, _data, function(res) {
			rn = eval('(' + res + ')');
			if (rn._status == 'error') {
				zebra_alert(rn.msg);
				return false;
			} else {
				// if($('.notice_check').html()==null){
				$(obj).parent().parent().append(rn.htm_str);
				// }
				$(obj).html('收起原因')
			}
		});

	},

	// 还原添加状态
	reset_n_add : function() {
		$('#title').val('');// 设置标题为空
		$('#post_value_id').val('');// 设置postid为空
		$('#post_key_id').val('');// 设置postkey为空
		$('#reset_mod_sender_id').hide();// 隐藏取消编辑按钮
		$('#mod_check_id').hide();// 隐藏未通过原因提示
		$('#radio_id').hide();// 隐藏选择人
		// $("#type_id")[0].checked=false;//设置提交复选框为false
		$('.notice_check').remove();// 移除未通过原因
		$(".iwk_postform_attachs").empty();// 附件为空
		$('#xz_wfl_id').text('请选择');
		$('#check_type_id').val('');
		// $('#mod_check_id')
		$('#mod_check_id').children().children().text('查看未通过原因');
		editor.html('');
		iwk_cfg_postform.temp_at_file = 0;
		iwk_cfg_postform.sending = 0;
		
		//初始化附件
		$('#postform_attach_queue').empty();
	},

	to_check : function(id) {
		var vid = '#iwk_notice_check_' + id;
		$.fancybox({
			'modal' : true,
			'scrolling' : 'no',
			'href' : vid,
			'helpers' : {
				overlay : {
					opacity : 0.2
				}
			},
			'beforeLoad' : function() {
				var inputSelector = 'input[name="' + id.substring(7)
						+ '_status_id"]';
				if ($.trim($("#single_notice_" + id).text()) == '') {
					$("#single_notice_" + id).pulldown2(
							{
								title : '通过',
								width : '90px',
								mode : 1,
								direction : 'left',
								fixed_options : [ {
									ttl : '通过',
									res : '1'
								}, {
									ttl : '不通过',
									res : '3'
								} ],
								event : function(self) {
									iwk_notice.onclick_select(self.get(0),
											inputSelector)
								}
							});
				} else {
					$("#single_notice_" + id).pulldown2('setVal', {
						ttl : '通过',
						res : '1'
					});
				}
				$(inputSelector).each(function() {
					$(this).val(1);
				});
			},
			'afterShow' : function() {
			}
		});
	},
	// 审核处使用
	onclick_select : function(obj, inputSelector) {
		$(inputSelector).each(function() {
			$(this).val($(obj).attr('data'));
		});
	}
};

var iwk_lconfig = {
	sorh : function(obj) {
		var obj = $(obj), o_id = obj.attr('data');
		obj.addClass('focus').siblings().removeClass('focus');
		$('.config_leave').hide();
		$('#' + o_id).show();
	},
	on_select : function(obj) {
		var sel_val = $(obj).attr('data');

		// alert(al_len);
		$(obj).parents('.fl').find('span').text($(obj).text());
		$(obj).parents('.fl').find('.grade_val').val(sel_val);

		switch (sel_val) {
		case '1':
			$(obj).parents('.config_leave').find('.l_t_2').hide();
			$(obj).parents('.config_leave').find('.l_t_3').hide();
			$(obj).parents('.config_leave').find('.l_t_4').hide();
			$(obj).parents('.config_leave').find('.l_t_5').hide();
			break;
		case '2':
			$(obj).parents('.config_leave').find('.l_t_2').show();
			$(obj).parents('.config_leave').find('.l_t_3').hide();
			$(obj).parents('.config_leave').find('.l_t_4').hide();
			$(obj).parents('.config_leave').find('.l_t_5').hide();
			break;
		case '3':
			$(obj).parents('.config_leave').find('.l_t_2').show();
			$(obj).parents('.config_leave').find('.l_t_3').show();
			$(obj).parents('.config_leave').find('.l_t_4').hide();
			$(obj).parents('.config_leave').find('.l_t_5').hide();
			break;
		case '4':
			$(obj).parents('.config_leave').find('.l_t_2').show();
			$(obj).parents('.config_leave').find('.l_t_3').show();
			$(obj).parents('.config_leave').find('.l_t_4').show();
			$(obj).parents('.config_leave').find('.l_t_5').hide();
			break;
		case '5':
			$(obj).parents('.config_leave').find('.l_t_2').show();
			$(obj).parents('.config_leave').find('.l_t_3').show();
			$(obj).parents('.config_leave').find('.l_t_4').show();
			$(obj).parents('.config_leave').find('.l_t_5').show();
			break;
		}
	},
	t_select : function(obj, data) {
		var $obj = $(obj);
		$obj.parents('.fl').find('span').text($(obj).text());

		$obj.parents('.fl').find('.t_val').val(data);

		if (data == 3) {
			$obj.parents('tr').find('.sel_pre').show();
		} else {
			$obj.parents('tr').find('.sel_pre').hide();
		}
		$obj.parents(".__flow_field__").next("div[data='sequence']").remove();
		if (data == 6) {
			var $temp = $("#_flow_sequence_template_ .__flow_field__sequence")
					.clone();
			$obj.parents(".__flow_field__").after($temp);
		}
	},
	sub_type : function(obj) {
		var _url = '' + 'ajax/config_data/';

		var v_data = new Array();
		// v_data ={};

		var l_list = $(obj).parents('.config_leave').find('.t_val');

		_url = _url + 'type:' + $(obj).attr('data');

		v_data = {};

		v_data['grade'] = $(obj).parents('.config_leave').find('.grade_val')
				.val();

		v_data['list'] = new Array();
		// alert(v_data['grade']);return false;
		for ( var i = 0; i < v_data['grade']; i++) {
			v_data['list'][i] = {};

			v_data['list'][i]['t_val'] = $(l_list[i]).val();

			v_data['list'][i]['level'] = i + 1;

			if (v_data['list'][i]['t_val'] == 3) {
				v_data['list'][i]['val_text'] = $(
						$(obj).parents('.config_leave').find('ol')[i]).find(
						'.user').attr('data');

				if (v_data['list'][i]['val_text'] == null) {
					zebra_alert('指定人员不能为空');
					return false;
				}

			}
		}

		if (v_data['grade'] != v_data['list'].length) {
			zebra_alert('数据有误,请重试');
			return false;
		}

		var _data = {
			p_data : v_data
		};

		$.post(_url, _data, function(res) {

			rn = eval('(' + res + ')');
			if (rn._status == 'ok') {
				// $(obj).parents('.leave').html(rn.html);
				zebra_alert(rn.msg);
			} else {
				zebra_alert('失败');
			}

		});
	},
	sub_con_notice : function(obj) {
		var _url = '' + 'ajax/config_data/type:notice/';

		v_data = {};

		v_data['c_status'] = $(obj).parents('.config_leave_table').find(
				'.c_status').val();

		if (v_data['c_status'] == 1) {
			var li_len = $(obj).parents('.config_leave_table').find('.sel_pre')
					.find('li').length;

			v_data['u_list'] = new Array();

			for ( var ei = 0; ei < li_len; ei++) {

				v_data['u_list'][ei] = $(
						$(obj).parents('.config_leave_table').find('.sel_pre')
								.find('li')[ei]).attr('data');

			}

			if (v_data['u_list'].length < 1) {
				zebra_alert('审核人不能为空');
				return false;
			}

		}

		var _data = {
			p_data : v_data
		};

		$.post(_url, _data, function(res) {

			rn = eval('(' + res + ')');
			if (rn._status == 'ok') {
				// $(obj).parents('.leave').html(rn.html);
				zebra_alert(rn.msg);
			} else {
				zebra_alert(rn.msg);
			}

		});

	},
	save_community_users : function(){
		var _data = $("#community_view_picker").userpicker("getData");
		_data.type = "community";
		$.post('' + 'ajax/report_config/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			zebra_alert(res.message);
		}, 'json');
	}, 
	che_onclick : function(obj) {
		var c_v = $(obj).find('.c_status').val();
		if (c_v == 0) {
			$(obj).find('span').addClass('checked');
			$(obj).find('.c_status').val('1');
			$(obj).parents('.config_leave_table').find('.check_user').show();
		} else {
			$(obj).find('span').removeClass('checked');
			$(obj).find('.c_status').val('0');
			$(obj).parents('.config_leave_table').find('.check_user').hide();
		}

	},
	save_report_afr : function() {
		var _data = $("#afr_view_picker").userpicker("getData");
		_data.type = "afr";
		$.post('' + 'ajax/report_config/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			zebra_alert(res.message);
		}, 'json');
	},
	save_report_leave : function() {
		var _data = $("#leave_view_picker").userpicker("getData");
		_data.type = "leave";
		$.post('' + 'ajax/report_config/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			zebra_alert(res.message);
		}, 'json');
	},
	save_report_workplan : function() {
		var _data = $("#workplan_view_picker").userpicker("getData");
		_data.type = "workplan";
		$.post('' + 'ajax/report_config/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			zebra_alert(res.message);
		}, 'json');
	},
	save_report_attend : function() {
		var _data = $("#attend_view_picker").userpicker("getData");
		_data.type = "attend";
		$.post('' + 'ajax/report_config/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			zebra_alert(res.message);
		}, 'json');
	},
	// 添加自定义字段
	add_one_field : function() {
		if($("#add_line").hasClass("disabled")){
			return false;
		}
		var $container = $("#__flow_field_container__");
		var $template = $("#__flow_field_template__");
		var $count = $container.find("div.__flow_field__").length;
		var _type_index = 99;

		$count++;
		if ($count > 10) {
			zebra_alert(iwk_lng.config_custom_filed_over);
			return;
		}

		// 修改LABEL
		$template.find("span.flow_custom_field_name:last").html(
				"自定义字段" + $count);

		var $contact = $template.find("div.__flow_field__").clone().show();
		$contact.find("font[name='__cus_contact_index__']").text($count);
		$container.append($contact);

		// 修改ID
		var filed_type = $container.find("div.__flow_field__:last").find(
				"div.single_custom_filed_type:last");
		filed_type.attr("id", "flow_filed_type" + $count);
		// 删除重复的title文本
		// $("#flow_filed_type"+$count).find(".widget_varsel:first").remove();

		$("#flow_filed_type" + $count).pulldown2({
			title : '请选择',
			width : '140px',
			mode : 1,
			zIndex : _type_index - $count,
			direction : 'left',
			fixed_options : [ {
				ttl : '文本（30字以内）',
				res : 1
			}, {
				ttl : '数字',
				res : 2
			}, {
				ttl : '时间',
				res : 3
			}, {
				ttl : '关联项目',
				res : 4
			}, {
				ttl : '关联客户',
				res : 5
			}, {
				ttl : '序列',
				res : 6
			} ],
			event : function(self) {
				var _data = self.data("val");
				iwk_lconfig.t_select(self.get(0), _data);
			}
		});

		$container.get(0).scrollTop = $container.get(0).scrollHeight;
	},
	_audit_index : 22,
	// 添加审核级次
	add_one_flow_level : function(_flow_level_data) {
		var $container = $("#__flow_level_container__");
		var $template = $("#__flow_level_template__");
		var $count = _flow_level_data;// $container.find("div.__flow_level__").length;

		// $count++;
		if ($count > 5) {
			zebra_alert(iwk_lng.config_custom_level_over);
			return;
		}

		// 清空
		$container.html("");

		for ( var i = 1; i <= $count; i++) {
			// 修改LABEL
			$template.find("span.flow_level_label:last").html("第" + i + "级审核人");

			var $contact = $template.find("div.__flow_level__").clone().show();
			$container.append($contact);

			// 修改ID
			$container.find("div.__flow_level__:last").find(
					"div.single_level_type_pulldown:last").attr("id",
					"flow_audit_level_val" + i);
			var audit_userpick = $container.find("div.__flow_level__:last")
					.find("div.single_level_audit_picker:last");
			audit_userpick.attr("id", "single_flow_multi" + i);

			$("#flow_audit_level_val" + i).pulldown2({
				title : '请选择',
				width : '110px',
				mode : 1,
				zIndex : iwk_lconfig._audit_index--,
				direction : 'left',
				fixed_options : [ {
					ttl : '直接上级',
					res : 1
				}, {
					ttl : '间接上级',
					res : 2
				}, {
					ttl : '指定人员',
					res : 3
				}, {
					ttl : '会审（全部）',
					res : 4
				}, {
					ttl : '会审（单一）',
					res : 5
				} ],
				event : function(self) {
					var _data = self.data("val");
					// iwk_lconfig.t_select(self.get(0), _data);
					iwk_lconfig.select_single_audit_type(self, _data);
				}
			});

			$("#single_flow_multi" + i).userpicker({
				placeholder : "+ 添加审核人",
				hint : "请输入搜索过滤",
				showUser : true,
				showGroup : false,
				disableOrg : true,
				multi : false,
				onChange : function(data) {
					// alert(JSON.stringify(data));
				}
			});
			$container.get(0).scrollTop = $container.get(0).scrollHeight;
		}
		$("#postform_body_customer").click(); // 修正IE7の奇葩错误 by xhj

	},
	// 编辑自定义字段
	add_one_field_edit : function(_data) {
		var $container = $("#__flow_field_container__");
		var $template = $("#__flow_field_template__");
		var $count = $container.find("div.__flow_field__").length;
		var _type_index = 99;

		$count++;
		if ($count > 10) {
			zebra_alert(iwk_lng.config_custom_filed_over);
			return;
		}

		// 修改LABEL
		$template.find("span.flow_custom_field_name:last").html(
				"自定义字段" + $count);

		var $contact = $template.find("div.__flow_field__").clone().show();
		$contact.find("font[name='__cus_contact_index__']").text($count);
		$container.append($contact);

		// 修改ID
		var filed_type = $container.find("div.__flow_field__:last").find(
				"div.single_custom_filed_type:last");
		filed_type.attr("id", "flow_filed_type" + $count);
		$("#flow_filed_type" + $count).pulldown2({
			title : '请选择',
			width : '140px',
			mode : 1,
			zIndex : _type_index - $count,
			direction : 'left',
			fixed_options : [ {
				ttl : '文本（30字以内）',
				res : 1
			}, {
				ttl : '数字',
				res : 2
			}, {
				ttl : '时间',
				res : 3
			}, {
				ttl : '关联项目',
				res : 4
			}, {
				ttl : '关联客户',
				res : 5
			}, {
				ttl : '序列',
				res : 6
			} ],
			event : function(self) {
				var _data = self.data("val");
				iwk_lconfig.t_select(self.get(0), _data);
			}
		});

		if ($.isPlainObject(_data)) {
			$("#flow_id").val(_data.wf_template_id);
			$container.find("div.__flow_field__:last").find(
					"input[name=flow_filed]").val(_data.field_name);
			$("#flow_filed_type" + $count).pulldown2('setVal', {
				ttl : _data.field_type.name,
				res : _data.field_type.id
			});
			if (_data.field_type.id == 6) {
				$("#flow_filed_type" + $count).parents(".__flow_field__").next(
						"div[data='sequence']").remove();
				var $temp = $(
						"#_flow_sequence_template_ .__flow_field__sequence")
						.clone();
				$temp.find(".flow_sequence").val(_data.option_value);
				$("#flow_filed_type" + $count).parents(".__flow_field__")
						.after($temp);
			}
			if (_data.is_required == 1) {
				$container.find("input[name=is_must]:last").attr("checked",
						"checked");
			}
		}

		$container.get(0).scrollTop = $container.get(0).scrollHeight;
	},
	// 添加审核级次
	add_one_flow_level_edit : function(_flow_level, _data) {
		var $container = $("#__flow_level_container__");
		var $template = $("#__flow_level_template__");
		var $count = _flow_level;// $container.find("div.__flow_level__").length;

		if ($count > 5) {
			zebra_alert(iwk_lng.config_custom_level_over);
			return;
		}

		var _audit_index = 22;
		// 修改LABEL
		$template.find("span.flow_level_label:last").html(
				"第" + _data.level_no + "级审核人");

		var $contact = $template.find("div.__flow_level__").clone().show();
		$container.append($contact);

		// 修改ID
		$container.find("div.__flow_level__:last").find(
				"div.single_level_type_pulldown:last").attr("id",
				"flow_audit_level_val" + _data.level_no);
		var audit_userpick = $container.find("div.__flow_level__:last").find(
				"div.single_level_audit_picker:last");
		audit_userpick.attr("id", "single_flow_multi" + _data.level_no);

		$("#flow_audit_level_val" + _data.level_no).pulldown2({
			title : '请选择',
			width : '110px',
			mode : 1,
			zIndex : iwk_lconfig._audit_index--,
			direction : 'left',
			fixed_options : [ {
				ttl : '直接上级',
				res : 1
			}, {
				ttl : '间接上级',
				res : 2
			}, {
				ttl : '指定人员',
				res : 3
			}, {
				ttl : '会审（全部）',
				res : 4
			}, {
				ttl : '会审（单一）',
				res : 5
			} ],
			event : function(self) {
				var _data = self.data("val");
				iwk_lconfig.select_single_audit_type(self, _data);
			}
		});
		if (typeof (_data.type) != "undefined" && _data.type.id == 3) {
			$("#single_flow_multi" + _data.level_no).userpicker({
				placeholder : "+ 添加审核人",
				hint : "请输入搜索过滤",
				showUser : true,
				showGroup : false,
				disableOrg : true,
				multi : false,
				onChange : function(data) {
					// alert(JSON.stringify(data));
				}
			});
		} else if (typeof (_data.type) != "undefined" && _data.type.id >= 3) {
			$("#single_flow_multi" + _data.level_no).userpicker({
				placeholder : "+ 添加审核人",
				hint : "请输入搜索过滤",
				showUser : true,
				showGroup : false,
				disableOrg : true,
				multi : true,
				onChange : function(data) {
					// alert(JSON.stringify(data));
				}
			});
		}

		if ($.isPlainObject(_data) && typeof (_data.type) != "undefined") {
			$("#flow_audit_level_val" + _data.level_no).pulldown2('setVal', {
				ttl : _data.type.name,
				res : _data.type.id
			});
			if (_data.type.id > 2) {
				var _default_user = new Array();
				for ( var i = 0; i < _data.audit_user.length; i++) {
					_default_user[i] = {
						data : _data.audit_user[i].id,
						name : _data.audit_user[i].name
					};
				}

				$("#single_flow_multi" + _data.level_no).userpicker("reload", {
					defaultUser : _default_user,
					showGroup : false,
					disableOrg : true,
					defaultGroup : [],
					defaultOrg : []
				});
				audit_userpick.show();
			} else {
				audit_userpick.hide();
			}
		}
		$container.get(0).scrollTop = $container.get(0).scrollHeight;

	},
	select_single_audit_type : function(_self, _data) {
		var _select = $(_self).parent().parent().parent();
		var _sel_id = _select.attr("id");
		var _count = _sel_id.substring("flow_audit_level_val".length,
				_sel_id.length);

		// 先清空层
		if ($("#single_flow_multi" + _count).length > 0) {
			$("#single_flow_multi" + _count).html("");
		}

		if (_data == 1 || _data == 2) {
			$("#single_flow_multi" + _count).hide();
		} else if (_data == 3) {
			$("#single_flow_multi" + _count).userpicker({
				placeholder : "+ 添加审核人",
				hint : "请输入搜索过滤",
				showUser : true,
				showGroup : false,
				disableOrg : true,
				multi : false,
				onChange : function(data) {
					// alert(JSON.stringify(data));
				}
			});
			$("#single_flow_multi" + _count).show();
		} else if (_data == 4 || _data == 5) {
			$("#single_flow_multi" + _count).userpicker({
				placeholder : "+ 添加审核人",
				hint : "请输入搜索过滤",
				showUser : true,
				showGroup : false,
				disableOrg : true,
				multi : true,
				onChange : function(data) {
					// alert(JSON.stringify(data));
				}
			});
			$("#single_flow_multi" + _count).show();
		}
	},
	// 保存自定义流程配置
	save_custom_flow : function() {
		var _data = {};
		var _id = $("#flow_id").val();
		var _name = $("#flow_name").val();
		var _levels = $("#flow_level_txt").val();
		;// $("#flow_level").pulldown2('getVal');

		if (_name === "") {
			zebra_alert(iwk_lng.config_custom_name_empty);
			return;
		}
		if (_id != null && _id != "") {
			_data.id = _id;
			_data.removed_attaches = iwk_cfg_postedit.removed_attaches
					.join(",");
		}

		_data.post_temp_id = iwk_cfg_postform.temp_id;
		_data.action = "new_flow";
		_data.name = _name;
		if (_levels && _levels != "") {
			_data.levels = _levels;
		} else {
			_data.levels = 1;
		}

		var _users = $("#flow_user_picker").userpicker("getData");
		if (_users && _users.number > 0) {
			// _data.users = _users.user;
			_data.assign_user = _users.user;
			_data.assign_group = _users.group;
			_data.assign_org = _users.org;
		} else {
			zebra_alert(iwk_lng.config_custom_user_empty);
			return false;
		}

		// 遍历自定义字段
		var _field_index = 0;
		var _field_rows = new Array();
		var _field_res = true;
		$("#__flow_field_container__").find(".__flow_field__").each(
				function() {

					var _field_data = {};
					var _field_name = $(this).find("input[name=flow_filed]")
							.val();
					var _field_type = $(this).find(".single_custom_filed_type")
							.pulldown2('getVal');

					if (_field_name != null && _field_name != "") {
						_field_data.field_name = _field_name;
						if (_field_type && _field_type.res) {
							_field_data.field_type = _field_type.res;
							// 如果为序列时
							if (_field_type.res == 6) {
								var _sequence = $(this).next(
										".__flow_field__sequence").find(
										".flow_sequence");
								if (_sequence.length != 0) {
									if ($.trim(_sequence.val()) == "") {
										zebra_alert("请输入第" + (_field_index + 1)
												+ "个自定义字段的序列选项");
										_field_res = false;
										return false;
									} else {
										_field_data.option_value = _sequence
												.val();
									}
								} else {
									_field_res = false;
									return false;
								}
							}
						} else {
							zebra_alert("第" + (_field_index + 1) + "个自定义字段"
									+ iwk_lng.config_custom_field_type_empty);
							_field_res = false;
							return false;
						}
						var _is_must = $(this).find("input[name=is_must]")
								.attr("checked");
						if (_is_must == "checked") {
							_field_data.is_required = 1;
						} else {
							_field_data.is_required = 0;
						}
						_field_data.level = 0;
						_field_rows[_field_index] = _field_data;
						_field_index++;
					}
				});
		if (_field_res) {
			_data.fields = _field_rows;
		} else {
			return false;
		}

		// 遍历审核级次
		var _level_index = 0;
		var _level_audits = new Array();
		var _level_res = true;
		$("#__flow_level_container__").find(".__flow_level__").each(
				function() {

					_level_datas = {};

					var _first_level = $(this).find(
							".single_level_type_pulldown").pulldown2('getVal'); // $("#flow_audit_level_val1").pulldown2('getVal');
					var _level_type = 1;
					if (_first_level && _first_level.res) {
						_level_type = _first_level.res;
					} else {
						zebra_alert("第" + (_level_index + 1) + "级"
								+ iwk_lng.config_custom_level_type_empty);
						_level_res = false;
						return false;
					}
					_level_datas['audit_type'] = _level_type;
					_level_datas['level_no'] = _level_index + 1;

					// 第一级选择了非直接上级和间接上级时，必须选择审核人
					if (_level_type != 1 && _level_type != 2) {
						var _first_audit = $(this).find(
								".single_level_audit_picker").userpicker(
								"getData");
						if (_first_audit.user == null
								|| _first_audit.user[0] == null
								|| _first_audit.user[0] == 0) {
							zebra_alert("第" + (_level_index + 1) + "级审核人不能为空");
							_level_res = false;
							return false;
						}

						if ((_level_type == 4 || _level_type == 5)
								&& _first_audit.user.length <= 1) {
							zebra_alert("第" + (_level_index + 1)
									+ "级类型为'会审'时，至少选择两人或两人以上");
							_level_res = false;
							return false;
						}

						_level_datas["audit_user"] = _first_audit.user;

					} else {
						_level_datas["audit_user"] = 0;
					}

					_level_audits[_level_index] = _level_datas;

					_level_index++;

				});
		if (_level_res) {
			_data.audits = _level_audits;
		} else {
			return false;
		}

		$.post('' + 'ajax/config/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			if (res.status.toLowerCase() == "ok") {
				zebra_alert("操作成功");
				window.location.href = document.URL;
				// iwk_lconfig.init_flow_postform();
			} else {
				zebra_alert(res.message);
			}
			$.fancybox.close();
		}, 'json');

	},
	// 初始化表单
	init_flow_postform : function() {
		iwk_cfg_postform.temp_id = iwk_common.get_new_guid();

		$("#flow_name").val("");
		$("#flow_user_picker").userpicker({
			placeholder : "+ 添加相关人",
			hint : "请输入搜索过滤",
			defaultUser : [ {
				data : iwk_cfg.my_id,
				name : iwk_cfg.my_name
			} ]
		});

		$("#__flow_field_container__").html("");
		$("#__flow_level_container__").html("");
		$("#flow_level").pulldown2({
			title : '1级',
			width : '60px',
			mode : 1,
			zIndex : 1000,
			direction : 'left',
			fixed_options : [ {
				ttl : '1级',
				res : 1
			}, {
				ttl : '2级',
				res : 2
			}, {
				ttl : '3级',
				res : 3
			}, {
				ttl : '4级',
				res : 4
			}, {
				ttl : '5级',
				res : 5
			} ],
			default_option : {
				ttl : '1级',
				res : 1
			},
			event : function(self) {
				var _data = self.data("val");
				$("#flow_level_txt").val(_data);
				iwk_lconfig.add_one_flow_level(_data);
			}
		});

	},
	// 自定义流程配置功能操作
	flow_proc : function(flow_id, type) {
		var _data = {
			"flow_id" : flow_id
		};
		_data.action = type;
		var _url = document.URL;
		$.post('' + 'ajax/config/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			if ($.trim(res.toLowerCase()) == 'ok') {
				zebra_auto('操作成功', 2000);
				window.location.href = _url;
			} else {
				zebra_alert(res);
			}
		}, 'json');

	},
	// 加载流程数据
	load_flow : function(flow_id, callback_after) {
		var _data = {
			"flow_id" : flow_id
		};
		_data.action = "load";
		$.post('' + 'ajax/config/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			if (res != null && res.status.toLowerCase() == "ok") {
				callback_after(res);
			} else {
				zebra_alert(res.message);
			}
		}, 'json');
	},
	// 显示流程编辑界面
	show_flow : function(flow_id) {
		iwk_lconfig.load_flow(flow_id, function(res) {
			if (res != null) {
				var _flow_data = res.data;
				var _wf_id = flow_id;
				var _wf_name = _flow_data.wf_name;
				var _wf_userlist = _flow_data.wf_user;
				var _wf_fields = _flow_data.fields;
				var _wf_audits = _flow_data.entrys;

				$("#flow_id").val(_wf_id);
				$("#flow_name").val(_wf_name);

				// 用户
				var _default_user = new Array();
				if (_wf_userlist && _wf_userlist.user) {
					for ( var i = 0; i < _wf_userlist.user.length; i++) {
						_default_user[i] = {
							data : _wf_userlist.user[i].id,
							name : _wf_userlist.user[i].name
						};
					}
				}
				var _default_org = new Array();
				if (_wf_userlist && _wf_userlist.org) {
					for ( var i = 0; i < _wf_userlist.org.length; i++) {
						_default_org[i] = {
							data : _wf_userlist.org[i].id,
							name : _wf_userlist.org[i].name
						};
					}
				}
				var _default_group = new Array();
				if (_wf_userlist && _wf_userlist.group) {
					for ( var i = 0; i < _wf_userlist.group.length; i++) {
						_default_group[i] = {
							data : _wf_userlist.group[i].id,
							name : _wf_userlist.group[i].name
						};
					}
				}

				$("#flow_user_picker").userpicker("reload", {
					placeholder : "+ 添加相关人",
					hint : "请输入搜索过滤",
					defaultUser : _default_user,
					defaultGroup : _default_group,
					defaultOrg : _default_org
				});

				$("#__flow_field_container__").html("");
				if (_wf_fields != null) {
					for ( var i = 0; i < _wf_fields.length; i++) {
						var field = _wf_fields[i];
						iwk_lconfig.add_one_field_edit(field);
					}
				}

				$("#__flow_level_container__").html("");
				if (_wf_audits != null) {
					$("#flow_level_txt").val(_flow_data.level);
					$("#flow_level").pulldown2('setVal', {
						ttl : _flow_data.level + "级",
						res : _flow_data.level
					});
					for ( var i = 0; i < _wf_audits.length; i++) {
						var entry = _wf_audits[i];
						iwk_lconfig.add_one_flow_level_edit(_flow_data.level,
								entry);
					}
				}

				iwk_lconfig.postform_attach_load(_flow_data);

				$("#iwk_postform").show();
				
				if(_flow_data.state == 1){
					var container = $("#__flow_field_container__");
					container.find(".widget_ipt_lite_wrap").addClass("disabled");
					container.find("input,textarea").attr("disabled","disabled");
					$("#add_line").addClass("disabled");
				}
			}
		});
	},

	set_removed_attach : function(_this) {
		zebra_confirm("确认删除此附件吗?", function() {
			var _id = $(_this).attr("data");
			iwk_cfg_postedit.removed_attaches.push(_id);
			$("#edit_flow_attach_" + _id).slideUp("slow", function() {
				$(this).remove();
			});
		});
	},
	append_attach_to_view : function(id, filename) {
		var _str = '<div id="edit_flow_attach_'
				+ id
				+ '" class="uploadify-queue-item">'
				+ '<div class="cancel">'
				+ '<a data="'
				+ id
				+ '" onclick="iwk_lconfig.set_removed_attach(this)" href="javascript:;">删除</a>'
				+ '</div>' + '<span class="fileName">' + filename + '</span>'
				+ '</div>';
		$(_str).appendTo("#postform_flow_attach_queue");
	},

	// 加载附件
	postform_attach_load : function(_data) {
		$("#postform_flow_attach_queue").html("");
		var attach = _data.attached;
		if (typeof (attach) == "undefined" || attach == "") {
			return;
		}
		$.each(attach, function(i, n) {
			var _id = n.attachment_id;
			var _type = n.attach_type;
			var _filename = n.title;
			iwk_lconfig.append_attach_to_view(_id, _filename);
		});
	},
	show_add_workflow : function() {
		$("#add_line").removeClass("disabled");
		iwk_lconfig.clear_all_workflow();
		$("#iwk_postform").toggle();
	},
	clear_all_workflow : function() {
		var _field_container = $("#__flow_field_container__");
		var _level_container = $("#__flow_level_container__");
		_field_container.empty();
		var _first_level_html = '<div class="__flow_level__" >';
		_first_level_html += '<div class="projt_cust_common_sty">';
		_first_level_html += '<span class="flow_level_label" style="float:left;width:100px;padding-left:20px;display:block;">第1级审核人</span>';
		_first_level_html += '<div id="flow_audit_level_val1" class="single_level_type_pulldown widget_ipt_lite_wrap fl " style="width:80px;margin-right:40px;">';
		_first_level_html += '</div>';
		_first_level_html += '<div style="float:left;">';
		_first_level_html += '<div id="single_flow_multi1" class="single_level_audit_picker widget_ipt_lite_wrap fl " style="width:480px;height:20px;;margin-top: -2px;">';
		_first_level_html += '</div>';
		_first_level_html += '</div>';
		_first_level_html += '<div class="klear"></div>';
		_first_level_html += '</div>';
		_first_level_html += '</div>';

		iwk_cfg_postform.temp_id = iwk_common.get_new_guid();
		iwk_cfg_postform.sending = 0;
		iwk_cfg_postform.attach_sending = 0;
		iwk_cfg_postform.removed_attaches.length = 0;
		_level_container.empty();
		_level_container.html(_first_level_html);
		$("#flow_id").val('');
		$("#flow_name").val('');
		$("#postform_flow_attach_queue").empty();
		$("#flow_level").pulldown2('setVal', {
			ttl : '1级',
			res : 1
		});
		$("#flow_user_picker").userpicker("reload", {
			defaultUser : [ {
				data : iwk_cfg.my_id,
				name : iwk_cfg.my_name
			} ],
			defaultGroup : [],
			defaultOrg : []
		});
		$("#flow_audit_level_val1").pulldown2({
			title : '请选择',
			width : '110px',
			mode : 1,
			zIndex : 66,
			direction : 'left',
			fixed_options : [ {
				ttl : '直接上级',
				res : 1
			}, {
				ttl : '间接上级',
				res : 2
			}, {
				ttl : '指定人员',
				res : 3
			}, {
				ttl : '会审（全部）',
				res : 4
			}, {
				ttl : '会审（单一）',
				res : 5
			} ],
			event : function(self) {
				var _data = self.data("val");
				iwk_lconfig.select_single_audit_type(self, _data);
			}
		});
	}
};

var iwk_search = {
	save_search_on : function(ajax_url) {
		$.post(ajax_url + '/r:' + Math.round(Math.random() * 1000),
				"savesearch=on", function(data) {
					var txt = jQuery.trim(data);
					if (txt.substr(0, 3) != "OK:") {
						return;
					}
					$("#savesearch").css('cursor', 'pointer').slideToggle()
							.hide();
					$("#remsearch").slideToggle().show();
					var _data = txt.split(":");
					$("#remsearch").attr("data", _data[1]);
					var search_key = $("input[name=lookfor]").val();
					var mdKey = _data[2];
					var _txt = '<a id="savesearch_id_' + _data[1] + '" href="'
							+ ajax_url + '/search/saved:' + mdKey
							+ '" class="ontag">' + search_key + '</a>';
					$(_txt).prependTo(".taglist");
					$("#savesearchresult").show();
				});
		$("#savesearch").css('cursor', 'wait');
	},
	save_search_off : function(ajax_url, confirm_msg) {
		$.post(ajax_url + '/r:' + Math.round(Math.random() * 1000),
				"savesearch=off", function(data) {
					var txt = jQuery.trim(data);
					if (txt.substr(0, 3) != "OK:") {
						return;
					}
					$("#remsearch").css('cursor', 'pointer').slideToggle()
							.hide();
					$("#savesearch").slideToggle().show();
					var saveid = $("#remsearch").attr("data");
					$("#savesearch_id_" + saveid).remove();
				});
		$("#savesearch").css('cursor', 'wait');
	}
};

// 日志JS对象
var iwk_workplan = {
	del : function(_posttmpid, callback_after, callback_onclose) {
		zebra_confirm(iwk_lng.plan_delete_confirm_msg, function() {
			var pid = _posttmpid.split("_");
			var _data = {
				type : 'delete',
				"postid" : pid[1]
			};
			$.post('' + 'apps/workplan/ajax/workplan-update/r:'
					+ Math.round(Math.random() * 1000), _data, function(res) {
				if ($.trim(res.toLowerCase()) == "ok")
					callback_after();
				else
					zebra_alert(iwk_lng.delete_error);
				$.fancybox.close();
			});
		}, null, callback_onclose);
	},
	getVal : function(obj){
		var obj_temp = obj.pulldown2("getVal");
		if(obj_temp){
			return(obj_temp.res);
		}
		return '';
	},
	create_report : function(){
		if(!iwk_workplan.getVal($("#flow_afr_option"))){
			zebra_alert("请先选择报表");
			return;
		}
		var _data = {};
		var fields = [];
		var fields_index = 0;
		var condition = {};
		condition.applicant = [$("#flow_user").userpicker("getData").user,$("#flow_user").userpicker("getData").org];
		if(iwk_workplan.getVal($("#flow_afr_auditstate")) != -1){
			condition.state = iwk_workplan.getVal($("#flow_afr_auditstate"));
		}
		var txts = $(".wk_report_txt");
		var sels = $(".wk_report_sel");
		txts.each(function(i,el){
			var jel = $(el);
			if(jel.val()){
				fields[fields_index] = {};
				fields[fields_index].id = jel.attr("data");
				fields[fields_index].type = jel.attr("data_type");
				fields[fields_index].value = $.trim(jel.val());
				fields_index++;
			}
		});
		sels.each(function(i,el){
			var jel = $(el);
			if(iwk_workplan.getVal(jel)){
				fields[fields_index] = {};
				fields[fields_index].id = $(el).attr("data");
				fields[fields_index].type = $(el).attr("data_type");
				fields[fields_index].value = iwk_workplan.getVal($(el)) == -1?0: iwk_workplan.getVal($(el)) ;
				fields_index++;
			}
		});
		condition.fields = fields;
		
		var audit_date_type = $("#audit_data_swap input[name='audit_date_radio']:checked").val();
		var audit_start = $("#search_audit_start_date").val();
		var audit_end = $("#search_audit_end_date").val();
		var now_date = new Date();
		if(audit_date_type == "custom"){
			condition.audit_start = iwk_date.formatStr(audit_start).getTime();
			condition.audit_end = iwk_date.formatStr(audit_end).getTime();
		}else if(audit_date_type == "month"){
			condition.audit_start = iwk_date.getMonthStartDay(now_date).getTime();
			condition.audit_end = iwk_date.getMonthEndDay(now_date).getTime();
		}else if(audit_date_type == "week"){
			condition.audit_start = iwk_date.getWeekStartDay(now_date).getTime();
			condition.audit_end = iwk_date.getWeekEndDay(now_date).getTime();
		}
		
		var date_type = $("#data_swap input[name='date_radio']:checked").val();
		var start = $("#search_start_date").val();
		var end = $("#search_end_date").val();
		if(date_type == "custom"){
			condition.start_time = iwk_date.formatStr(start).getTime();
			condition.end_time = iwk_date.formatStr(end).getTime();
		}else if(date_type == "month"){
			condition.start_time = iwk_date.getMonthStartDay(now_date).getTime();
			condition.end_time = iwk_date.getMonthEndDay(now_date).getTime();
		}else if(date_type == "week"){
			condition.start_time = iwk_date.getWeekStartDay(now_date).getTime();
			condition.end_time = iwk_date.getWeekEndDay(now_date).getTime() ;
		}
		
		if(condition.start_time){
			condition.start_time = condition.start_time/1000;
		}
		if(condition.end_time){
			condition.end_time = condition.end_time/1000+86400;
		}
		if(condition.audit_start){
			condition.audit_start = condition.audit_start/1000;
		}
		if(condition.audit_end){
			condition.audit_end = condition.audit_end/1000+86400;
		}
		
		_data.condition = JSON.stringify(condition);
		_data.flow_id = iwk_workplan.getVal($("#flow_afr_option"));
		if($("#values").val()){
			_data.values = $("#values").val();
		}
		fancylay.block();
		//重置datagrid和table，否则下次查询无法控制高度
		$(".panel.datagrid").remove();
		$('<table id="reportTable" class=""  data-options="rownumbers:true">').appendTo($("#iwk_wide_right"));
		$.post('' + 'apps/flow/workplan_report/from:ajax/r:' + Math.round(Math.random() * 1000), _data, function(data) {
			data=data.match(/{"frozenColumns.*]}]}/)[0];
			var obj = jQuery.parseJSON(data);
			$("#data_detail").val(data);
			$("#reportTable").addClass("easyui-datagrid");
			if(obj.data[0].rows.length > 19){
				document.getElementById("reportTable").style.width="800px";
				document.getElementById("reportTable").style.height="514px";
        	}
			var options = {  
		            loadMsg:"正在加载数据,请稍候...", 
		            frozenColumns: obj.frozenColumns,
		            columns: obj.columns,
		            scrollbarSize:10,
		            onLoadSuccess:function(data){
		                var table = $("#reportTable");
		                var rows=table.datagrid("getRows");
		                for(var i = 0;i < rows.length;i++){
		                	if(rows[i].org == "部门小计" || rows[i].org == "合计"){
		                		table.datagrid("mergeCells",{
		                			index:i,
		                			field:'org',
		                			colspan:2
		                		});
		                	}
		                }
		            },
		            rowStyler:function(index,row){
		            	if(row.org == '部门小计'){
		            		return 'background-color:#F0F2F3';
		            	}
		            	if(row.org == '合计'){
		            		return 'background-color:#cccfd3';
		            	}
		            },
		            onClickRow:function(index,data){
		            	if(data.org == "部门小计"){
		            		iwk_workplan.create_report_detail(data.user_id,data.org_id);
		            		return;
		            	}
		            	if(data.org == "合计"){
		            		iwk_workplan.create_report_detail();
		            		return;
		            	}
		            	iwk_workplan.create_report_detail(data.user_id,data.org_id);
		            }
		    	    }; 
			$("#reportTable").datagrid(options);//调用扩展方法，创建表格列
			$("#reportTable").datagrid("loadData", obj.data[0]);
			fancylay.unblock();
		});
	},
	//ex_user用于接收从汇总表点击一行时的用户
	create_report_detail : function(ex_user,ex_org){
		if(!iwk_workplan.getVal($("#flow_afr_option"))){
			zebra_alert("请先选择报表");
			return;
		}
		var _data = {};
		var fields = [];
		var fields_index = 0;
		var condition = {};
		condition.applicant = [$("#flow_user").userpicker("getData").user,$("#flow_user").userpicker("getData").org];
		if(typeof ex_user == "string" || typeof ex_org == "string"){
			if(!ex_user){
				ex_user = "";
			}
			if(!ex_org){
				ex_org = "";
			}
			condition.applicant = [[ex_user],[ex_org]];
		}
		if(iwk_workplan.getVal($("#flow_afr_auditstate")) != -1){
			condition.state = iwk_workplan.getVal($("#flow_afr_auditstate"));
		}
		var txts = $(".wk_report_txt");
		var sels = $(".wk_report_sel");
		txts.each(function(i,el){
			var jel = $(el);
			if(jel.val()){
				fields[fields_index] = {};
				fields[fields_index].id = jel.attr("data");
				fields[fields_index].type = jel.attr("data_type");
				fields[fields_index].value = $.trim(jel.val());
				fields_index++;
			}
		});
		sels.each(function(i,el){
			var jel = $(el);
			if(iwk_workplan.getVal(jel)){
				fields[fields_index] = {};
				fields[fields_index].id = $(el).attr("data");
				fields[fields_index].type = $(el).attr("data_type");
				fields[fields_index].value = iwk_workplan.getVal($(el))==-1?0:iwk_workplan.getVal($(el));
				fields_index++;
			}
		});
		condition.fields = fields;
		
		var audit_date_type = $("#audit_data_swap input[name='audit_date_radio']:checked").val();
		var audit_start = $("#search_audit_start_date").val();
		var audit_end = $("#search_audit_end_date").val();
		var now_date = new Date();
		if(audit_date_type == "custom"){
			condition.audit_start = iwk_date.formatStr(audit_start).getTime();
			condition.audit_end = iwk_date.formatStr(audit_end).getTime();
		}else if(audit_date_type == "month"){
			condition.audit_start = iwk_date.getMonthStartDay(now_date).getTime();
			condition.audit_end = iwk_date.getMonthEndDay(now_date).getTime();
		}else if(audit_date_type == "week"){
			condition.audit_start = iwk_date.getWeekStartDay(now_date).getTime();
			condition.audit_end = iwk_date.getWeekEndDay(now_date).getTime();
		}
		
		var date_type = $("#data_swap input[name='date_radio']:checked").val();
		var start = $("#search_start_date").val();
		var end = $("#search_end_date").val();
		if(date_type == "custom"){
			condition.start_time = iwk_date.formatStr(start).getTime();
			condition.end_time = iwk_date.formatStr(end).getTime();
		}else if(date_type == "month"){
			condition.start_time = iwk_date.getMonthStartDay(now_date).getTime();
			condition.end_time = iwk_date.getMonthEndDay(now_date).getTime();
		}else if(date_type == "week"){
			condition.start_time = iwk_date.getWeekStartDay(now_date).getTime();
			condition.end_time = iwk_date.getWeekEndDay(now_date).getTime() ;
		}
		
		if(condition.start_time){
			condition.start_time = condition.start_time/1000;
		}
		if(condition.end_time){
			condition.end_time = condition.end_time/1000+86400;
		}
		if(condition.audit_start){
			condition.audit_start = condition.audit_start/1000;
		}
		if(condition.audit_end){
			condition.audit_end = condition.audit_end/1000+86400;
		}
		
		_data.condition = JSON.stringify(condition);
		_data.flow_id = iwk_workplan.getVal($("#flow_afr_option"));
		if($("#values").val()){
			_data.values = $("#values").val();
		}
		var merge_col = 1;
		if($("#txt_values").val()){
			_data.txt_values = $("#txt_values").val();
			merge_col = JSON.parse(_data.txt_values).length;
		}
		
		fancylay.block();
		//重置datagrid和table，否则下次查询无法控制高度
		$(".panel.datagrid").remove();
		$('<table id="reportTable" class=""  data-options="rownumbers:true">').appendTo($("#report_body_wrap"));
		$.post('' + 'apps/flow/workplan_report/from:ajax_detail/r:' + Math.round(Math.random() * 1000), _data, function(data) {
			var obj = jQuery.parseJSON(data);
			
			//format 数据，加上超链接
			for(var i = 0;i < obj.data[0].rows.length;i++){
				var row_obj=obj.data[0].rows[i];
				if(row_obj["org"] == "合计" || row_obj["org"] == "部门小计" || row_obj["user"] == "小计"){
					continue;
				}
				for(var item in row_obj){
					if(item == "url"){
						continue;
					}
					if(item == "content"){
						row_obj[item] ="<a class='aline' href='"+row_obj["url"]+"' title='"+row_obj[item]+"' target='_blank'>"+row_obj[item]+"</a>";
					}else{
						row_obj[item] ="<a class='aline' href='"+row_obj["url"]+"' target='_blank'>"+row_obj[item]+"</a>";
					}
				}
			}
			
			$("#reportTable").addClass("easyui-datagrid");
			if(obj.data[0].rows.length > 19){
				document.getElementById("reportTable").style.width="800px";
				document.getElementById("reportTable").style.height="514px";
        	}
			$("#data_detail").val(data);
			var options = {  
		            loadMsg:"正在加载数据,请稍候...", 
		            frozenColumns: obj.frozenColumns,
		            columns: obj.columns,
		            scrollbarSize:10,
		            onLoadSuccess:function(data){
		                $(".datagrid").addClass("report_detail");
		                var table = $("#reportTable");
		                var rows=table.datagrid("getRows");
		                for(var i = 0;i < rows.length;i++){
		                	if(rows[i].org == "部门小计" || rows[i].org == "合计"){
		                		table.datagrid("mergeCells",{
		                			index:i,
		                			field:'content',
		                			colspan:merge_col
		                		});
		                		table.datagrid("mergeCells",{
		                			index:i,
		                			field:'org',
		                			colspan:2
		                		});
		                	}
		                }
		            },
		            rowStyler:function(index,row){
		            	if(row.org == '部门小计'){
		            		return 'background-color:#cccfd3';
		            	}
		            	if(row.org == '合计'){
		            		return 'background-color:#b3b4b5';
		            	}
		            	if(row.user == '小计'){
		            		return 'background-color:#F0F2F3';
		            	}
		            }
//		            onClickRow : function(index,data){
//		            	if(data.org == "部门小计" || data.org == "合计"){
//		            		return;
//		            	}
//		            	window.location.href = data.url;
//		            }
		    	    }; 
			$("#reportTable").datagrid(options);//调用扩展方法，创建表格列
			$("#reportTable").datagrid("loadData", obj.data[0]);
			fancylay.unblock();
		});
	},
	import_report : function(){
		if(!iwk_workplan.getVal($("#flow_afr_option"))){
			zebra_alert("请先选择报表");
			return;
		}
		if(!$("#data_detail").val()){
			var _data = {};
			var fields = [];
			var fields_index = 0;
			var condition = {};
			condition.applicant = [$("#flow_user").userpicker("getData").user,$("#flow_user").userpicker("getData").org];
			if(iwk_workplan.getVal($("#flow_afr_auditstate")) != -1){
				condition.state = iwk_workplan.getVal($("#flow_afr_auditstate"));
			}
			var txts = $(".wk_report_txt");
			var sels = $(".wk_report_sel");
			txts.each(function(i,el){
				var jel = $(el);
				if(jel.val()){
					fields[fields_index] = {};
					fields[fields_index].id = jel.attr("data");
					fields[fields_index].type = jel.attr("data_type");
					fields[fields_index].value = jel.val();
					fields_index++;
				}
			});
			sels.each(function(i,el){
				var jel = $(el);
				if(iwk_workplan.getVal(jel)){
					fields[fields_index] = {};
					fields[fields_index].id = $(el).attr("data");
					fields[fields_index].type = $(el).attr("data_type");
					fields[fields_index].value = iwk_workplan.getVal($(el));
					fields_index++;
				}
			});
			condition.fields = fields;
			
			var audit_date_type = $("#audit_data_swap input[name='audit_date_radio']:checked").val();
			var audit_start = $("#search_audit_start_date").val();
			var audit_end = $("#search_audit_end_date").val();
			var now_date = new Date();
			if(audit_date_type == "custom"){
				condition.audit_start = audit_start;
				condition.audit_end = audit_end;
			}else if(audit_date_type == "month"){
				condition.audit_start = iwk_date.getMonthStartDay(now_date).getTime();
				condition.audit_end = iwk_date.getMonthEndDay(now_date).getTime();
			}else if(audit_date_type == "week"){
				condition.audit_start = iwk_date.getWeekStartDay(now_date).getTime();
				condition.audit_end = iwk_date.getWeekEndDay(now_date).getTime();
			}
			
			var date_type = $("#data_swap input[name='date_radio']:checked").val();
			var start = $("#search_start_date").val();
			var end = $("#search_end_date").val();
			if(date_type == "custom"){
				condition.start_time = start;
				condition.end_time = end;
			}else if(date_type == "month"){
				condition.start_time = iwk_date.getMonthStartDay(now_date).getTime();
				condition.end_time = iwk_date.getMonthEndDay(now_date).getTime();
			}else if(date_type == "week"){
				condition.start_time = iwk_date.getWeekStartDay(now_date).getTime();
				condition.end_time = iwk_date.getWeekEndDay(now_date).getTime() ;
			}
			
			_data.condition = JSON.stringify(condition);
			_data.flow_id = iwk_workplan.getVal($("#flow_afr_option"));
			if($("#values").val()){
				_data.values = $("#values").val();
			}
			if($("#txt_values").val()){
				_data.txt_values = $("#txt_values").val();
			}
			$.post('' + 'apps/flow/workplan_report/from:'+$("#import").val()+'/r:' + Math.round(Math.random() * 1000), _data, function(data) {
				$("#data_detail").val(data);
				$('#report_form').submit();
			});
		}else{
			$('#report_form').submit();
		}
	},
	switch_workplan : function(_flow_id){
		iwk_postform.load_flow_data(_flow_id, function(res){
			var _data = res.data;
			$("#import_title").val(_data.wf_name+"报表");
			$("#report_title").html(_data.wf_name+"报表");
			var report_more= $("#report_more");
			var _field_arr = [];
			var _proj_cust_arr = [];
			var values = [];
			var txt_values = [];
			var txt_values_pro = [];
			//自定义字段
			for ( var i = 0; i < _data.fields.length; i++) {
				var _field = _data.fields[i];
				if (_field.field_type == 1){
					_field_arr.push('<div class="more_line">');
					_field_arr.push('<div class="report_name">');
					_field_arr.push(_field.field_name);
					_field_arr.push(':</div><div class="widget_ipt_lite_wrap">');
					_field_arr.push('<input data="');
					_field_arr.push(_field.id);
					_field_arr.push('" data_type="');
					_field_arr.push(1);
					_field_arr.push('"  type="text"  name="other_flow_text" class="widget_ipt_lite wk_report_txt" placeholder="小文本(30字以内)" maxlength="30">');
					_field_arr.push('</div><div class="klearboth"></div></div>');
					
					txt_values.push('{"id":"'+_field.id+'","val":"'+_field.field_name+'"}');
				}
				if(_field.field_type == 2){
					values.push('{"id":"'+_field.id+'","val":"'+_field.field_name+'"}');
				}
				if(_field.field_type == 3){
					txt_values.push('{"id":"'+_field.id+'","val":"'+_field.field_name+'"}');
				}
				if (_field.field_type == 4){
					_proj_cust_arr.push('<div class="more_line">');
					_proj_cust_arr.push('<div class="report_name">');
					_proj_cust_arr.push(_field.field_name);
					_proj_cust_arr.push(':</div>');
					_proj_cust_arr.push('<div class="plan_report_project wk_report_sel" data="');
					_proj_cust_arr.push(_field.id);
					_proj_cust_arr.push('" data_type="');
					_proj_cust_arr.push(4);
					_proj_cust_arr.push('" name="other_flow_sec" ></div>');
					_proj_cust_arr.push('<div class="klearboth"></div></div>');
					
					txt_values_pro.push('{"id":"'+_field.id+'","type":4,"val":"'+_field.field_name+'"}');
				}
				if (_field.field_type == 5){
					_proj_cust_arr.push('<div class="more_line">');
					_proj_cust_arr.push('<div class="report_name">');
					_proj_cust_arr.push(_field.field_name);
					_proj_cust_arr.push(':</div>');
					_proj_cust_arr.push('<div class="plan_report_customer wk_report_sel" data="');
					_proj_cust_arr.push(_field.id);
					_proj_cust_arr.push('" data_type="');
					_proj_cust_arr.push(5);
					_proj_cust_arr.push('" name="other_flow_sec"></div>');
					_proj_cust_arr.push('<div class="klearboth"></div></div>');
					
					txt_values_pro.push('{"id":"'+_field.id+'","type":5,"val":"'+_field.field_name+'"}');
				}
				if (_field.field_type == 6){
					_field_arr.push('<div class="more_line">');
					_field_arr.push('<div class="report_name">');
					_field_arr.push(_field.field_name);
					_field_arr.push(':</div>');
					_field_arr.push('<div class="wk_report_sel" data="');
					_field_arr.push(_field.id);
					_field_arr.push('" data_type="');
					_field_arr.push(6);
					_field_arr.push('" name="other_flow_sec"  ></div>');
					_field_arr.push('<div class="klearboth"></div></div>');
					
					txt_values.push('{"id":"'+_field.id+'","val":"'+_field.field_name+'"}');
				}
			}
			if(values.length!=0){
				$("#values").val("["+values.join(",")+"]");
			}else{
				$("#values").val("");
			}
			if(txt_values_pro.length != 0){
				txt_values.push(txt_values_pro.join(","));
			}
			if(txt_values.length!=0){
				$("#txt_values").val("["+txt_values.join(",")+"]");
			}else{
				$("#txt_values").val("");
			}
			_field_arr.push(_proj_cust_arr.join(""));
			_field_arr.push('<div class="klearboth"></div>');
			report_more.html(_field_arr.join(""));
			
			var _zindex = 20;
			//激活序列 项目 客户的下拉选项功能
			if (_data.fields && _data.fields.length>0){
				for ( var i = 0; i < _data.fields.length; i++) {
					var _field = _data.fields[i];
					if (_field.field_type == 6){
						var options = _field.option_value.split(",");
						var option_json = [{ttl:'全部',res:0}];
						for(var j = 0;j < options.length;j++){
							option_json[j+1] = {};
							option_json[j+1].ttl = options[j];
							option_json[j+1].res = options[j];
						}
						$(".wk_report_sel[data="+_field.id+"]").pulldown2({
							zIndex:_zindex--,
							title: '全部',
							mode: 1,
							width: 219,
							fixed_options: option_json,
							event: function(self){
								
							}
						});
					}
				}
			}
			
			$(".plan_report_project").pulldown2({
				zIndex: 5,
				title: '所有',
				url: '' + 'apps/project/ajax/pagi_projects',
				empty_text: '无关联项目',
				field: 'name',
				width:219,
				cutlen: 10,
				val:0,
				default_option: {
					ttl: '所有',
					res: 0
				},
				header_option:[{
					ttl:'无',
					res:-1
				}]
			});
			
			$(".plan_report_customer").pulldown2({
				zIndex: 5,
				title: '所有',
				cutlen: 10,
				width:219,
				url: ''+'apps/customer/ajax/pagi_customers',
				empty_text: '无关联客户',
				field: 'customer_name',
				val:0,
				default_option: {
					ttl: '所有',
					res: 0
				},
				header_option:[{
					ttl:'无',
					res:-1
				}]
			});
		});
		$("#data_detail").val("");
	},
	status_arr:["未完成","完成","超期完成","超期"],
	remove_task_tip:function(e){
		var obj = $(e.target);
		$("#sch_tip_task").hide();
	},
	add_task_tip: function(e)
	{
		var obj = $(e.target);
		var _data = e.data.m[obj.data("search_id")];
		var _pop = $("#sch_tip_task");
		
		_pop.find(".s_sender span").html(_data.assigner);
		_pop.find(".s_actor span").html(_data.excutor);
		_pop.find(".s_time span").html(_data.start+ " — " + _data.end);
		_pop.find(".s_state span").html(iwk_workplan.status_arr[obj.data("status")]);
		_pop.find(".s_text").html(_data.task);
		
		_pop.find(".s_project").hide();
		_pop.find(".s_customer").hide();
		if(_data.project){
			_pop.find(".s_project").show().find("span").html(_data.project);
		}
		if(_data.customer){
			_pop.find(".s_customer").show().find("span").html(_data.customer);
		}
		
		iwk_common.stop_propagation(e);
		
		var _left = e.pageX - 27;
		_pop.find(".triangle").css("left", 15);
		if( e.pageX + _pop.width() > $(window).width() ){
			_left = e.pageX - _pop.width() + 38;
			_pop.find(".triangle").css("left", 269);
		}
		var _top = obj.offset().top + 35;
		_left -= $("#iwk_page").offset().left;
		_top -= $("#iwk_page").offset().top;;
		_pop.css({left: _left, top: _top + 25});
		_pop.show().stop(true, false).animate({top: _top});
	},
	create_gantt : function() {
		var keyword= $.trim($("#search_string").val());
		var executor = {user:$("#executor_wrap").userpicker("getData").user,org:$("#executor_wrap").userpicker("getData").org};
		var gantt_begin= $("#gantt_begin").val();
		var gantt_end= $("#gantt_end").val();
		var gantt_state= $("#gantt_state").pulldown2("getVal").res;
		var project_temp = $("#gantt_project").pulldown2("getVal");
		//格式化日期，开始日期为本周日，结束日期为本周六
		gantt_begin_true = iwk_date.formatStr(gantt_begin).getTime();
		gantt_end_true = iwk_date.formatStr(gantt_end).getTime();
		gantt_begin = iwk_date.getWeekStartDay(iwk_date.formatStr(gantt_begin)).getTime();
		gantt_end = iwk_date.getWeekEndDay(iwk_date.formatStr(gantt_end)).getTime();
		
		if((gantt_end_true-gantt_begin_true)/86400000>180){
			zebra_alert("最长查询区间为180天，请重新设置");
			return false;
		}
		
		var project;
		if(project_temp && project_temp.res){
			project = project_temp.res;
		}
		var customer_temp = $("#gantt_customer").pulldown2("getVal");
		var customer;
		if(customer_temp && customer_temp.res){
			customer= customer_temp.res;
		}
//		var sort_temp= $("#gantt_sort").pulldown2("getVal");
//		var sort;
//		if(sort_temp){
//			sort= sort_temp.res;
//		}
		
		var _data ={};
		if(keyword){_data.keyword=keyword;}
		for(var i = 0;i < executor.org.length;i++){
			if(executor.org[i] == 0){
				executor.org.splice(i,1);
			}
		}
		if(executor.org.length!=0  || executor.user.length != 0){_data.executor=executor;}
		if(gantt_begin){_data.gantt_begin=gantt_begin;}
		if(gantt_end){_data.gantt_end=gantt_end;}
		if(gantt_begin_true){_data.gantt_begin_true=gantt_begin_true;}
		if(gantt_end_true){_data.gantt_end_true=gantt_end_true;}
		if(gantt_state){_data.gantt_state=gantt_state;}
		if(project){_data.project=project;}
		if(customer){_data.customer=customer; }
//		if(sort != undefined){_data.sort=sort;}
		_data.sort = 2;
		fancylay.block();
		//重置datagrid和table，否则下次查询无法控制高度
		$(".panel.datagrid").remove();
		$('<table id="reportTable" class="hide"  rownumbers="true"></table>').appendTo($("#iwk_wide_right"));
		$.post('' + 'apps/task/ganttview/from:ajax/r:' + Math.round(Math.random() * 1000), _data, function(data) {
			var obj = jQuery.parseJSON(data);
			
			var report_table = $("#reportTable");
			report_table.addClass("easyui-datagrid");
			if(obj.data[0].rows.length > 18){
				document.getElementById("reportTable").style.width="800px";
				document.getElementById("reportTable").style.height="514px";
        	}
			var options = {  
		            loadMsg:"正在加载数据,请稍候...", 
		            frozenColumns: obj.frozenColumns,
		            columns: obj.columns,
		            scrollbarSize:10,
		            data:obj.data[0],
		            onLoadSuccess:function(data){
		            	var d1 = new Date().getTime();
		            	if (data.rows.length>0){
	                	var cells = $(".datagrid-view2 .datagrid-body .datagrid-cell");
	                	for(var i = 0,l=cells.length;i<l;i++){
	                		var cell = $(cells[i]);
	                		var _parent = cell.parent();
	                		switch(cell.text()){
	                		case "2":
	                			cell.addClass("task_show gantt_task_show_green");
	                			var row_index =_parent.parent().attr("datagrid-row-index");
	                			cell.data("search_id",row_index);
	                			cell.data("status",2);
	                			cell.text("");
	                			_parent.css("border-right-color","#88C184");
	                			break;
	                		case "0":
	                			cell.addClass("task_show gantt_task_show_blue");
	                			var row_index = _parent.parent().attr("datagrid-row-index");
	                			cell.data("search_id",row_index);
	                			cell.data("status",0);
	                			cell.text("");
	                			_parent.css("border-right-color","#78B1EC");
	                			break;
	                		case "1":
	                			cell.addClass("task_show gantt_task_show_green");
	                			var row_index = _parent.parent().attr("datagrid-row-index");
	                			cell.data("search_id",row_index);
	                			cell.data("status",1);
	                			cell.text("");
	                			_parent.css("border-right-color","#88C184");
	                			break;
	                		case "3":
	                			cell.addClass("task_show gantt_task_show_red");
	                			var row_index = _parent.parent().attr("datagrid-row-index");
	                			cell.data("search_id",row_index);
	                			cell.data("status",3);
	                			cell.text("");
	                			_parent.css("border-right-color","#E68C8C");
	                			break;
	                		}
	                	}
	                }
		            	var d2 = new Date().getTime();
		                $(".datagrid-view2 .datagrid-btable").delegate(".task_show","mouseover",{m:data.rows},iwk_workplan.add_task_tip);
		                $(".datagrid-view2 .datagrid-btable").delegate(".task_show","mouseout",iwk_workplan.remove_task_tip);
		            },
		            onClickRow:function(index,data){
		            	window.open(data.url);
		            }
		    	    }; 
		    	$("#reportTable").datagrid(options);//调用扩展方法，创建表格列
				fancylay.unblock();
		});
	},
	create_task_grade_report:function(){
		var keyword= $.trim($("#search_string").val());
		var executor = {user:$("#executor_wrap").userpicker("getData").user,org:$("#executor_wrap").userpicker("getData").org};
		var gantt_begin= $("#gantt_begin").val();
		var gantt_end= $("#gantt_end").val();
		var gantt_state= $("#gantt_state").pulldown2("getVal").res;
		var project_temp = $("#gantt_project").pulldown2("getVal");
		//格式化日期，开始日期为本周日，结束日期为本周六
		gantt_begin_true = iwk_date.formatStr(gantt_begin).getTime();
		gantt_end_true = iwk_date.formatStr(gantt_end).getTime();
		gantt_begin = iwk_date.getWeekStartDay(iwk_date.formatStr(gantt_begin)).getTime();
		gantt_end = iwk_date.getWeekEndDay(iwk_date.formatStr(gantt_end)).getTime();
		
		if((gantt_end_true-gantt_begin_true)/86400000>180){
			zebra_alert("最长查询区间为180天，请重新设置");
			return false;
		}
		
		var project;
		if(project_temp && project_temp.res){
			project = project_temp.res;
		}
		var customer_temp = $("#gantt_customer").pulldown2("getVal");
		var customer;
		if(customer_temp && customer_temp.res){
			customer= customer_temp.res;
		}
//		var sort_temp= $("#gantt_sort").pulldown2("getVal");
//		var sort;
//		if(sort_temp){
//			sort= sort_temp.res;
//		}
		
		var _data ={};
		if(keyword){_data.keyword=keyword;}
		for(var i = 0;i < executor.org.length;i++){
			if(executor.org[i] == 0){
				executor.org.splice(i,1);
			}
		}
		if(executor.org.length!=0  || executor.user.length != 0){_data.executor=executor;}
		if(gantt_begin){_data.gantt_begin=gantt_begin;}
		if(gantt_end){_data.gantt_end=gantt_end;}
		if(gantt_begin_true){_data.gantt_begin_true=gantt_begin_true;}
		if(gantt_end_true){_data.gantt_end_true=gantt_end_true;}
		if(gantt_state){_data.gantt_state=gantt_state;}
		_data.gantt_grade_state=$("#gantt_grade_state").pulldown2("getVal").res;
		if(project){_data.project=project;}
		if(customer){_data.customer=customer; }
//		if(sort != undefined){_data.sort=sort;}
		_data.sort = 2;
		fancylay.block();
		//重置datagrid和table，否则下次查询无法控制高度
		$(".panel.datagrid").remove();
		$('<table id="reportTable" class="hide"  rownumbers="true"></table>').appendTo($("#iwk_wide_right"));
		$.post('' + 'apps/task/task_grade_report/from:ajax/r:' + Math.round(Math.random() * 1000), _data, function(data) {
			data=data.match(/{"frozenColumns.*]}]}/)[0];
			var obj = jQuery.parseJSON(data);
			
			//按执行人排序并增加平均分
			if(obj.data[0].rows.length!=0){
				obj.data[0].rows.sort(function(a,b){
					if(a.executor != b.executor){
						return a.executor.localeCompare(b.executor);
					}else if(a.start != b.start){
						return a.start.localeCompare(b.start);
					}else{
						return a.end.localeCompare(b.end);
					}
				});
				if(_data.gantt_grade_state != 2){
					var before_str = obj.data[0].rows[0].executor;
					var grade_sum = 0;
					var grade_count = 0;
					var rows = [];
					var index = -1;
					for(var i = 0;i < obj.data[0].rows.length;i++){
						if(before_str != obj.data[0].rows[i].executor){
							rows[++index]={};
							rows[index].executor = before_str;
							if(grade_count != 0){rows[index].grade = (grade_sum/grade_count).toFixed(2)};
							rows[index].task = "任务平均分";
							rows[index].org = obj.data[0].rows[i-1].org;
							before_str = obj.data[0].rows[i].executor;
							grade_sum = 0;
							grade_count = 0;
						}
						rows[++index]=obj.data[0].rows[i];
						if(obj.data[0].rows[i].grade){
							grade_sum += parseFloat(obj.data[0].rows[i].grade);
							grade_count++;
						}
					}
					rows[++index]={};
					rows[index].executor = before_str;
					if(grade_count != 0){rows[index].grade = (grade_sum/grade_count).toFixed(2)};
					rows[index].task = "任务平均分";
					rows[index].org = obj.data[0].rows[obj.data[0].rows.length-1].org;
					obj.data[0].rows = rows;
				}
			}
			
			//format数据，加上超链接
			for(var i = 0;i < obj.data[0].rows.length;i++){
				var row_obj=obj.data[0].rows[i];
				if(row_obj.task == "任务平均分"){
					continue;
				}
				for(var item in row_obj){
					if(item == "url"){
						continue;
					}
					var _val = row_obj[item]?row_obj[item]:"";
					if(item == "task" || item == "evaluate_desc"){
						row_obj[item] ="<a class='aline' href='"+row_obj["url"]+"' title='"+_val+"' target='_blank'>"+_val+"</a>";
					}else{
						row_obj[item] ="<a class='aline' href='"+row_obj["url"]+"' target='_blank'>"+_val+"</a>";
					}
					if(!row_obj.grade){
						row_obj.grade ="<a class='aline' href='"+row_obj["url"]+"' target='_blank'></a>";
						row_obj.evaluater ="<a class='aline' href='"+row_obj["url"]+"' target='_blank'></a>";
						row_obj.evaluate_desc ="<a class='aline' href='"+row_obj["url"]+"' target='_blank'></a>";
					}
				}
			}
			
			var report_table = $("#reportTable");
			report_table.addClass("easyui-datagrid");
			if(obj.data[0].rows.length > 18){
//				document.getElementById("reportTable").style.width="800px";
				document.getElementById("reportTable").style.height="514px";
        	}
			var options = {  
		            loadMsg:"正在加载数据,请稍候...", 
		            columns: obj.frozenColumns,
		            scrollbarSize:10,
		            data:obj.data[0],
		            onLoadSuccess:function(data){
		            	$(".datagrid").addClass("report_detail");
		            	var table = $("#reportTable");
		            	for(var i = 0;i < data.rows.length;i++){
		            		if(data.rows[i].task == "任务平均分"){
		            			table.datagrid("mergeCells",{
		                			index:i,
		                			field:'task',
		                			colspan:3
		                		});
		            		}
		            	}
		            },
		            rowStyler:function(index,row){
		            	if(row.task == '任务平均分'){
		            		return 'background-color:#cccfd3';
		            	}
		            } 
		    	    }; 
		    	$("#reportTable").datagrid(options);//调用扩展方法，创建表格列
				fancylay.unblock();
		});
	},
	// 删除单条发贴按钮(自己的发贴)
	workplan_delete : function(_this, _posttmpid) {
		iwk_workplan.del(_posttmpid, function() {
			$("#sp_" + _posttmpid).slideUp('slow', function() {
				$(_this).remove();
			});
		});
	},

	load_evaluate : function(_this, _posttmpid) {
		var pid = _posttmpid.split("_");
		var _data = {
			type : 'readeval',
			"postid" : pid[1]
		};
		$.post('' + 'apps/workplan/ajax/workplan-update/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			if (res != null && res.status.toLowerCase() == "ok") {
				if (res.data.point > 0) {
					$("#form_point").val(res.data.point);
				}
				$("#form_evaluate_desc").val(res.data.content);
			}
		}, 'json');
	},

	evaluate_form_show : function(_this, _pid) {
		$.fancybox({
			'modal' : true,
			'scrolling' : 'visible',
			'href' : '#iwk_workplan_form_evaluate',
			'helpers' : {
				overlay : {
					opacity : 0.2
				}
			},
			'beforeLoad' : function() {
				$("#form_point").val("");
				$("#form_evaluate_desc").val("");
				$("#form_evaluate_pid").val(_pid);
				// iwk_workplan.load_evaluate(_this, _pid);
			},
			'beforeShow' : function() {
				iwk_workplan.load_evaluate(_this, _pid);
			}
		});
	},

	// 提交评价
	evaluate_workplan : function() {
		var _posttmpid = $("#form_evaluate_pid").val();
		if (_posttmpid == null || _posttmpid == "") {
			zebra_alert(iwk_lng.plan_not_select);
			return;
		}
		var pid = _posttmpid.split("_");
		var _point = $("#form_point").val();
		var _content = $("#form_evaluate_desc").val();
		var _data = {
			type : 'evaluate',
			postid : pid[1],
			content : _content
		};

		if (_point < 0 || _point > 10) {
			zebra_alert(iwk_lng.plan_error_point);
			return;
		}

		if (_point != "") {
			_data.point = _point;
			// }else{
			// _data.point = -1;
		}

		fancylay.block();
		$.post('' + 'apps/workplan/ajax/workplan-update/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {
			if (res.status.toLowerCase() == 'ok') {
				iwk_post.synchronize_single(_posttmpid);
			} else {
				zebra_alert(res.message);
			}
			fancylay.unblock();
			$.fancybox.close();
		}, 'json');

	},
	create_statistics : function(){
		var _data ={};
		var _executor = $("#executor_wrap").userpicker("getData");
		if(_executor.number > 0){
			_data.number = _executor.number;
			_data.user = _executor.user.join(",");
			_data.org = _executor.org.join(",");
			$("#number").val(_data.number);
			$("#user").val(_data.user);
			$("#org").val(_data.org);
		}else{
			_data.number = 0;
			$("#number").val(_data.number);
			$("#user").val("");
			$("#org").val("");
		}
		
		var date_type = $("#data_swap input[name='date_radio']:checked").val();
		var start = $("#search_start_date").val();
		var end = $("#search_end_date").val();

		if(date_type == "custom"){
			_data.date_type = date_type;
			_data.start = start;
			_data.end = end;
			$("#date_type").val(date_type);
			$("#start").val(start);
			$("#end").val(end);
		}else{
			_data.date_type = date_type;
			$("#date_type").val(date_type);
			$("#start").val("");
			$("#end").val("");
		}
		_data.sort = $("#statistics_sort").pulldown2("getVal").res;
		$("#sort").val(_data.sort);
		fancylay.block();
		//重置datagrid和table，否则下次查询无法控制高度
		$(".panel.datagrid").remove();
		$('<table id="reportTable" class="hide"  rownumbers="true"></table>').appendTo($("#iwk_wide_right"));
		$.post('' + 'apps/task/statistics/from:ajax/r:' + Math.round(Math.random() * 1000), _data, function(res) {
			res = jQuery.parseJSON(res);
			if(res.data[0].data[0].rows.length > 18){
				document.getElementById("reportTable").style.width="800px";
				document.getElementById("reportTable").style.height="514px";
        	}
			$("#search_start_hid").val(iwk_date.formatDate(new Date(res.start*1000)));
			$("#search_end_hid").val(iwk_date.formatDate(new Date(res.end*1000)));
			var ajax_data = res.data[0];
			var options = {  
		        loadMsg:"正在加载数据,请稍候...", 
		        columns: ajax_data.columns,
		        data:ajax_data.data[0],
		        onLoadSuccess:function(data){
		        	$(".datagrid-btable td[field=total]").click(function(){iwk_workplan.open_task("all",this)});
		        	$(".datagrid-btable td[field=finished]").click(function(){iwk_workplan.open_task("finished",this)});
		        	$(".datagrid-btable td[field=unfinished]").click(function(){iwk_workplan.open_task("running",this)});
		        	$(".datagrid-btable td[field=overtime]").click(function(){iwk_workplan.open_task("overtime",this)});
		        }
		    }; 
			$("#reportTable").datagrid(options);//调用扩展方法，创建表格列
			fancylay.unblock();
		});
	},
	import_report2 : function(){
		if(!$("#date_type").val()){
			zebra_alert("请先生成报表");
			return;
		}
		$("#report_form").submit();
	},
	open_task : function(_state,_this){
		var _start = $("#search_start_hid").val();
		var _end = $("#search_end_hid").val();
		var _id = $(_this).closest("tr").find("td:first div").html();
		var _count = $.trim($(_this).find("div.datagrid-cell").html());
		window.open(''+"apps/task/statistics_detail/to_user:"+_id+"/state:"+_state+"/date_type:custom/start:"+_start+"/end:"+_end+"/count:"+_count);
	},
	create_using_analysis : function(){
		var _data ={};
		var _executor = $("#executor_wrap").userpicker("getData");
		if(_executor.number > 0){
			_data.number = _executor.number;
			_data.user = _executor.user.join(",");
			_data.org = _executor.org.join(",");
			$("#number").val(_data.number);
			$("#user").val(_data.user);
			$("#org").val(_data.org);
		}else{
			_data.number = 0;
			$("#number").val(_data.number);
			$("#user").val("");
			$("#org").val("");
		}
		
		var date_type = $("#data_swap input[name='date_radio']:checked").val();
		var start = $("#search_start_date").val();
		var end = $("#search_end_date").val();

		if(date_type == "custom"){
			_data.date_type = date_type;
			_data.start = start;
			_data.end = end;
			$("#date_type").val(date_type);
			$("#start").val(start);
			$("#end").val(end);
		}else{
			_data.date_type = date_type;
			$("#date_type").val(date_type);
			$("#start").val("");
			$("#end").val("");
		}
		_data.sort = $("#statistics_sort").pulldown2("getVal").res;
		$("#sort").val(_data.sort);
		fancylay.block();
		//重置datagrid和table，否则下次查询无法控制高度
		$(".panel.datagrid").remove();
		$('<table id="reportTable" class="hide"  rownumbers="true"></table>').appendTo($("#iwk_wide_right"));
		$.post('' + 'apps/task/using_analysis/from:ajax/r:' + Math.round(Math.random() * 1000), _data, function(res) {
			res = jQuery.parseJSON(res);
			console.log(res.data[0].data[0].rows.length);
			if(res.data[0].data[0].rows.length > 18){
				document.getElementById("reportTable").style.width="800px";
				document.getElementById("reportTable").style.height="514px";
        	}
			var ajax_data = res.data[0];
			var options = {  
		        loadMsg:"正在加载数据,请稍候...", 
		        columns: ajax_data.columns,
		        data:ajax_data.data[0],
		        onLoadSuccess:function(data){

		        }
		    }; 
			$("#reportTable").datagrid(options);//调用扩展方法，创建表格列
			fancylay.unblock();
		});
	}
}

// 自定义流程JS对象
var iwk_workflow = {
	sendding : 0,
	workflow_print : function(_postid) {
		window.open('' + 'apps/workplan/print/post:' + _postid,
				"_blank");
		return false;
	},
	add_active_data : function(arr, arr_audit) {
		var arr_html = [];
		var index = 1;
		arr_html.push("<li>");
		for ( var i = 0; i < arr.length; i++) {
			if (1 < Number(arr[i].field_type) && Number(arr[i].field_type) < 4) {
				if (index == 1) {
					arr_html.push('<div class="promt_name">');
					arr_html.push(arr[i].field_name);
					arr_html
							.push('</div><div class="colon">:</div><div class="promt_value value_short">');
					arr_html.push(arr[i].field_value);
					arr_html.push('</div>');
					index++;
				} else {
					arr_html.push('<div class="promt_name2">');
					arr_html.push(arr[i].field_name);
					arr_html
							.push('</div><div class="colon">:</div><div class="promt_value value_short">');
					arr_html.push(arr[i].field_value);
					arr_html.push('</div><div class="klearboth"></div></li>');
					arr_html.push('<li>');
					index = 1;
				}
			} else {
				if (index == 2) {
					arr_html.push('<div class="klearboth"></div></li><li>');
				}
				arr_html.push('<div class="promt_name">');
				arr_html.push(arr[i].field_name);
				arr_html.push('</div><div class="colon">:</div><div class="promt_value">');
				if(arr[i].field_type==4){
					arr_html.push(arr[i].project.name);
				}else if(arr[i].field_type==5){
					arr_html.push(arr[i].customer.customer_name);
				}else{
					arr_html.push(arr[i].field_value);
				}
				arr_html.push('</div><div class="klearboth"></div></li>');
				arr_html.push('<li>');
				index = 1;
			}
		}
		if (index == 1) {
			arr_html.pop();
		} else {
			arr_html.push('<div class="klearboth"></div></li>');
		}

		arr_html.push('<li class="bottom">');
		for ( var i in arr_audit) {
			arr_html.push('<div class="approval">');
			switch(arr_audit[i][0].level_no){
			case "1":
				arr_html.push("<div class='btm_name'>一级审批：</div>");
				break;
			case "2":
				arr_html.push("<div class='btm_name'>二级审批：</div>");
				break;
			case "3":
				arr_html.push("<div class='btm_name'>三级审批：</div>");
				break;
			case "4":
				arr_html.push("<div class='btm_name'>四级审批：</div>");
				break;
			case "5":
				arr_html.push("<div class='btm_name'>五级审批：</div>");
				break;
			}
			for(var j in arr_audit[i]){
				if(j % 3==0 && j!=0){
					arr_html.push("<div class='btm_val' style='margin-left:70px;'>");
				}else{
					arr_html.push("<div class='btm_val'>");
				}
				arr_html.push(arr_audit[i][j].audit_user.fullname);
				arr_html.push(" ");
				arr_html.push(new Date(Number(arr_audit[i][0].audit_time*1000))
				.format("yyyy-MM-dd"));
				arr_html.push("</div>");
			}
			arr_html.push('</div>');
		}
		arr_html.push('<div class="klearboth"></div></li>');
		var ul = $("#workplan_print ul");
		ul.append(arr_html.join(""));
	},
	del : function(_posttmpid, callback_after, callback_onclose) {
		zebra_confirm(iwk_lng.plan_delete_confirm_msg, function() {
			var pid = _posttmpid.split("_");
			var _data = {
				type : 'delete',
				"postid" : pid[1]
			};
			_data.action = "delete";
			$.post('' + 'ajax/workflow/r:'
					+ Math.round(Math.random() * 1000), _data, function(res) {
				if ($.trim(res.toLowerCase()) == "ok")
					callback_after();
				else
					zebra_alert(iwk_lng.delete_error);
				$.fancybox.close();
			});
		}, null, callback_onclose);
	},
	// 删除单条发贴按钮(自己的发贴)
	workflow_delete : function(_this, _posttmpid) {
		iwk_workflow.del(_posttmpid, function() {
			$("#sp_" + _posttmpid).slideUp('slow', function() {
				$(_this).remove();
			});
		});
	},
	workflow_transfer : function(_this, _postid) {
		$.fancybox({
			'modal' : false,
			'scrolling' : 'no',
			'href' : '#foot_common_user_picker',
			'helpers' : {
				overlay : {
					opacity : 0.2
				}
			},
			'beforeLoad' : function() {
				$("#fcup_multipicker").userpicker("clear");
				$("#foot_common_user_picker .btn").hide();
				$("#fcup_btn_workflow").show();
				$("#fcup_textarea").val('').hide();
				$("#fcup_ipt_workflow_id").val('');
				$("#fcup_ipt_workflow_id").val(_postid);
			},
			'afterShow' : function() {

			}
		});
	},
	transfer_ok : function() {
		var _r = $("#fcup_multipicker").userpicker("getData");
		if (_r.user && _r.user[0]) {
			$.fancybox.close();
			var _data = {
				"userid" : _r.user[0],
				"action" : "transfer"
			};

			_data.postid = $("#fcup_ipt_workflow_id").val();
			var _display = $("#fcup_textarea").css("display");
			if (_display == 'none') {
				_data.reason = '';
			} else {
				_data.reason = $("#fcup_textarea").val();
			}

			$.post('' + 'ajax/workflow/r:'
					+ Math.round(Math.random() * 1000), _data, function(res) {
				if (res.status.toLowerCase() == 'ok') {
					if (iwk_cfg.page_name == 'view') {
						iwk_post.synchronize_single(_data.postid);
					} else {
						iwk_post.synchronize();
					}
				}
				zebra_alert(res.message);
			}, 'json');
		} else {
			zebra_alert("请选择用户!");
		}
	},

	// 审核
	audit : function(_this, _post_id, _state, callback) {
		var _data = {
			"postid" : _post_id
		};
		_data.state = _state;
		_data.action = "audit";

		if (iwk_afr.sending) {
			return;
		}

		iwk_workflow.sending = 1;
		$.post('' + 'ajax/workflow/r:'
				+ Math.round(Math.random() * 1000), _data,
				function(res) {
					if (!jQuery.isEmptyObject(res)
							&& res.status.toLowerCase() == 'ok') {
						callback();
					} else {
						zebra_alert(res.message);
					}
					iwk_workflow.sending = 0;
				}, 'json');
	},

	workflow_audit : function(_this, _post_id, _state) {
		var __this = $(_this);
		if (__this.attr('handling') != 'true') {
			__this.attr('handling', 'true');
			iwk_workflow.audit(_this, _post_id, _state, function() {
				if (iwk_cfg.page_name == 'view') {
					iwk_post.synchronize_single(_post_id);
				} else {
					iwk_post.synchronize();
				}
				__this.attr('handling', 'false');
			});
		}
	},

	// 打回按钮
	callback : function(_this, _post_id, callback) {
		// 阻塞
		fancylay.block();
		var _data = {
			"postid" : _post_id,
			"action" : "callback"
		};
		$.post('' + 'ajax/workflow/r:'
				+ Math.round(Math.random() * 1000), _data, function(res) {

			$.fancybox.hideLoading();
			if (res.status == 'OK') {
				// 撤销阻塞
				fancylay.unblock();
			} else {
				fancylay.unblock();
				// zebra_alert(res.message);
			}
			callback(res);
		}, 'json');
	},

	workflow_callback : function(_this, _post_id) {
		iwk_workflow.callback(_this, _post_id, function(res) {
			if (iwk_cfg.page_name == 'view') {
				iwk_post.synchronize_single(_post_id);
			} else {
				iwk_post.synchronize();
			}
			zebra_alert(res.message);
		});
	}
}

var iwk_call = {
		data0:'',
		data1:'',//用于表示查询出来的所有数据
		data2:'',//私信选组界面查询数据
		data3:'',//通话过程中查询数据
		data4:'',//继续添加成员时添加界面数据
		_me:'',
		recallings:[],//表示正在重拨的id
		kicking:[],
		init:function(_data,_me){
			var _ul=[];
			_ul.push('<ul id="call_sellist" class="call_ul">');
			var _index = 0;
			var _count_users = 0;
			for(var i = 0;i < _data.length;i++){
				if(_data[i].id && _data[i].id == _me.id){
					continue;
				}
				switch(_data[i].type){
//				case "org":
//					_index++;
//					_ul.push('<li class="call_li call_org" listtag="list'+_index+'"><a>');
//					_ul.push(_data[i].name);
//					_ul.push('</a></li>');
//					break;
				case "user":
					var _class="";
					var _title = '';
					if(_data[i].mobile.search(/^\d{10,12}$/)==-1){
						_class="call_li call_person call_nophone";
					}else{
						_class="call_li call_person";
					}
					_ul.push('<li data="');
					_ul.push(_data[i].id);
					_ul.push('" class="');
					_ul.push(_class);
					_ul.push(" list"+_index);
					_ul.push(" list"+_index);
					_ul.push('"><a><span class="call_name">');
					_ul.push(_data[i].name);
					_ul.push('</span><span class="call_tel"');
					_ul.push(_title);
					_ul.push('>');
					_ul.push(_data[i].mobile);
					_ul.push('</span>');
					_ul.push('</a></li>');
					_count_users++;
					break;
				}
			}
			_ul.push('</ul>');
			var _rightli = [];
			_rightli.push('<li data="');
			_rightli.push(_me.id);
			_rightli.push('" class="');
			_rightli.push("call_li call_person call_disabled");
			_rightli.push('"><a><span class="call_name">');
			_rightli.push(_me.fullname+'(主持人)');
			_rightli.push('</span><span class="call_tel">');
			_rightli.push(_me.mobile?_me.mobile:(_me.work_mobile==""?_me.phone:_me.work_mobile));
			_rightli.push('</span>');
			_rightli.push('</a></li>');
			$("#call_selectedlist").html(_rightli.join(""));
			$("#call_sel").removeClass("loading_wrap").html(_ul.join(""));
			$("#sel_title_count").html("(<span id='sel_title_selected'data='1'>1</span>/10)");
			iwk_call.data1 = $("#call_sellist").html();
		},
		switch_priv:function(){
			$(".tab:not(.tab2)").removeClass("focus");
			$(".tab2").addClass("focus");
			$("#call_left").hide();
			$("#call_right").hide();
			$("#call_footer").hide();
			$('#priv_footer').show();
			$("#priv_body").show();
			var _data = {'action':'priv_group'};
			$.post( '' + "inside/apply_call/r:" + Math.round(Math.random() * 1000), _data, function(res) {
				iwk_call.data2 = res;
				var li_arrs = [];
				if(res.length==0){
					$("div.call_priv_head").text('(当前没有通话记录)');
				}else{
					$("div.call_priv_head").text('选择一个私信群组启动电话会议');
				}
				for(var i = 0;i < res.length;i++){
					var index = 0;
					var li_arr = [];
					var li_content = "";
					for(var j in res[i].prv_user_info){
						if(index >= 4){
							index++;
							continue;
						}
						li_arr.push(res[i].prv_user_info[j].fullname);
						index++;
					}
					if(index > 4){
						li_content = li_arr.join("、")+"等"+index+"人";
					}else{
						li_content = li_arr.join("、");
					}
					li_arrs.push('<li><img src="') ;
					li_arrs.push(res[i].prv_avatar+'">');
					li_arrs.push('<div class="priv_users">');
					li_arrs.push(li_content);
					li_arrs.push('</div>');
					li_arrs.push('<div class="radio" style=""><span class=""><input type="radio" name="date_radio" value="');
					li_arrs.push(i);
					li_arrs.push('" style="opacity: 0;"></span></div>');
					li_arrs.push('<div class="klearboth"></div></li>');
				}
				$("#priv_loading").hide();
				$("#priv_ul").html(li_arrs.join(""));
			},'json');
		},
		edit_phone:function(event){
			var _this = $(this);
			var _phone = '';
			if(_this.prev().prev().html().search(/^\d{10,12}$/)!=-1){
				_phone =_this.prev().prev().html() ;
			}
			_this.prev().val(_phone).show().focus().prev().hide();
		},
		finish_phone:function(){
			var _this = $(this);
			var _checker = _this.prevAll(".widget_checker");
			var _val = $.trim(_this.val());
			if(_val != "" && _val.search(/^\d{10,12}$/) == -1){
				_checker.find("span").removeClass("checked");
				_checker.find("input").prop("checked",false);
				zebra_alert("请输入正确的号码，座机请加区号",function(){_this.focus();});
				return;
			}else{
				if(_val == ""){
					_this.hide().prev().html("请点击编辑输入电话").removeClass().addClass("prep_phone prep_phone_empty").show();
					if(_checker.is(".disabled")){
						return;
					}
					_checker.find("span").removeClass("checked");
					_checker.find("input").prop("checked",false);
					return;
				}else{
					_this.hide().prev().html(_val).removeClass("prep_phone_empty").show();
					_checker.find("span").addClass("checked");
					_checker.find("input").prop("checked",true);
				}
			}
			
			var $lis = $(iwk_call.data4);
			var _arr = [];
			for(var i = 0;i < $lis.length;i++){
				var $li = $($lis[i]);
				if($li.attr("data") == _this.parent().attr("data")){
					$li.find("div.prep_phone").html(_val);
					$li.find(".widget_checker span").addClass("checked");
					$li.find(".widget_checker input").prop("checked",true);
				}
				_arr.push($li.get(0).outerHTML);
			}
			iwk_call.data4 = _arr.join("");
		},
		switch_call:function(){
			$(".tab:not(.tab1)").removeClass("focus");
			$(".tab1").addClass("focus");
			$("#call_left").show();
			$("#call_right").show();
			$("#call_footer").show();
			$('#priv_footer').hide();
			$("#priv_body").hide();
		},
		test_call:function(){
			var _data = {};
			_data.action = "test_call";
			fancylay.block();
			$.post( '' + "inside/apply_call/r:" + Math.round(Math.random() * 1000), _data, function(res) {
				res = JSON.parse(res);
				switch(res.status){
				case 20000 :
					zebra_alert(res.mes);
					break;
				case 20003 :
					iwk_call.contact_iwk(res.mes);
					//zebra_confirm(res.mes,iwk_call.contact_iwk);
					break;
				case 20002 :
					iwk_call.add_com(res.mes);
					break;
				case 20001 :
					zebra_alert(res.mes);
					break;
				case "ok"  :				
					//iwk_call.contact_iwk(res.mes);
					$("#call_action").val(res.status);
					iwk_call._me.mobile==""?(iwk_call._me.work_mobile==""?iwk_call._me.phone:iwk_call._me.work_mobile):iwk_call._me.mobile;
					if(iwk_call._me && iwk_call._me.mobile.search(/^\d{10,12}$/)==-1){
						iwk_call._me.mobile = "";
						iwk_call._me.work_mobile = "";
						iwk_call._me.phone = "";
					}
					iwk_call.call_exp(res.me);
					iwk_call._me = res.me;
					break;
				}
				fancylay.unblock();
			});
		},
		contact_service: function(){
			window.open('http://sighttp.qq.com/authd?IDKEY=7a954562eac6ba8cf3a861fbe8089e116e65ab89d8a5caa0');
		},
		contact_iwk:function(mes){
			$.fancybox({
	    		modal: true,
	    		//scrolling: "visible",
	    		href: "#call_service_wrap",
	    		helpers: {overlay: {opacity: 0.2}},
	    		padding:0,
	    		beforeLoad: function(){
	    		}
	    	});			
		},
		add_com:function(mes){
			$.fancybox({
	    		modal: true,
	    		//scrolling: "visible",
	    		href: "#call_addusers_wrap",
	    		helpers: {overlay: {opacity: 0.2}},
	    		padding:0,
	    		beforeLoad: function(){
	    		}
	    	});			
		},
		call_exp:function(_me){
			//成功
			$.fancybox({
	    		modal: true,
	    		//scrolling: "visible",
	    		href: "#call_pop_wrap",
	    		helpers: {overlay: {opacity: 0.2}},
	    		padding:0,
	    		beforeLoad: function(){
	    			
	    		},
	    		afterShow : function(){
	    			$(".fancybox-inner").css({'overflow':'hidden'});
	    		}
	    	});
			var _data ={
				    "text": "",
				    "type": "org",
				    "group": [],
				    "org": [],
				    "is_private_group": true,
				    "user_scope_group": [],
				    "scope_group": [],
				    "with_special_group": true,
				    "show_group": true,
				    "show_org": true,
				    "all":true
				};
			$.post( '' + "ajax/pagi_userpicker/r:" + Math.round(Math.random() * 1000), _data, function(res) {
				res.data.sort(function(a,b){
					return a.name.localeCompare(b.name);
				});
				for(var i = 0;i < res.data.length;i++){
					res.data[i].mobile = res.data[i].mobile == ""?(res.data[i].work_mobile==""?res.data[i].phone:res.data[i].work_mobile):res.data[i].mobile;
					if(res.data[i].mobile && res.data[i].mobile.search(/^\d{10,12}$/)==-1){
						res.data[i].mobile = "";
					}
				}
				iwk_call.init(res.data,_me);
				iwk_call.data0 = res.data;
			},'json');
		},
		clear_step1_data:function(){
			//清空通话人数据
			$("#call_selectedlist").empty();
			$("#call_sellist").empty();
			iwk_call.left_data = '';
			iwk_call.data1 = '';
			$("#sel_input").val("");
			$("#call_sel").addClass("loading_wrap").html('<div id="call_loading"><div></div></div>');
			
			//清空私信数据
			$("#priv_ul").html("");
			$("#priv_loading").show();
			
			//切换tab至通话人
			iwk_call.switch_call();
		},
		call_close:function(){
			$.fancybox.close();
			iwk_call.clear_step1_data();
			iwk_call.clear_all_data();
		},
		add_all:function(){
			$("#call_selectedlist").append($("#call_sellist li:not(.call_disabled)"));
			var _dis = $("#call_sellist li.call_disabled");
			$("#call_sellist").empty().append(_dis);
		},
		reselect:function(){
			$("#call_selectedlist li").remove(":not(.call_disabled)");
			$("#call_sel").html('<ul id="call_sellist" class="call_ul">'+iwk_call.data1+'</ul>');
		},
		search:function(_data){
			right_datas = $("#call_selectedlist").html().match(/<li.*?<\/li>/gi);
			var data_all = iwk_call.data1;
			if(right_datas){
				for(var i = 0;i < right_datas.length;i++){
					data_all = data_all.replace(right_datas[i],"");
				}
			}
			
			_data = $.trim(_data);
			var result = [];
			var index = 0;
			var $left = $(data_all);
			var _len = $left.length;
			for(var i = 0;i < _len;i++){
				var spans =$( $left[i]).find("span");
				for(var j= 0;j < spans.length;j++){
					if($(spans[j]).text().search(_data)!=-1){
						result[index++] = $left[i];
						break;
					}
				}
			}
			$("#call_sellist").empty().append(result);
		},
		sel_search:function(_data){	
			right_datas = $("#prepare_userpick_selectedlist").html().match(/<li.*?<\/li>/gi);
			var data_all = iwk_call.data4;
			if(right_datas){
				for(var i = 0;i < right_datas.length;i++){
					data_all = data_all.replace(right_datas[i],"");
				}
			}				
			_data = $.trim(_data);
			var result = [];
			var index = 0;
			var $left = $(data_all);
			var _len = $left.length;
			for(var i = 0;i < _len;i++){
				var spans =$( $left[i]).find("span");
				for(var j= 0;j < spans.length;j++){		
					if($(spans[j]).text().search(_data)!=-1){
						result[index++] = $left[i];
						break;
					}
				}
			}
			$("#userpick_sellist").empty().append(result);
		},
		finish_search:function(_data){	
			right_datas = $("#finish_userpick_selectedlist").html().match(/<li.*?<\/li>/gi);
			var data_all = iwk_call.data4;
			if(right_datas){
				for(var i = 0;i < right_datas.length;i++){
					data_all = data_all.replace(right_datas[i],"");
				}
			}				
			_data = $.trim(_data);
			var result = [];
			var index = 0;
			var $left = $(data_all);
			var _len = $left.length;
			for(var i = 0;i < _len;i++){
				var spans =$( $left[i]).find("span");
				for(var j= 0;j < spans.length;j++){		
					if($(spans[j]).text().search(_data)!=-1){
						result[index++] = $left[i];
						break;
					}
				}
			}
			$("#finish_userpick_sellist").empty().append(result);
		},
		start_call:function(){
			iwk_call.data4 = "";
			$("#continue_invite").hide();
			$("#end_call").hide();
			var first_phone = $("#prepare_ul li:first div.prep_phone");
			if(first_phone.html().search(/^\d{10,12}$/) == -1){
				zebra_alert("请先输入主持人电话号码，座机请加区号",function(){
					setTimeout(function(){first_phone.nextAll("div.prep_edit").click();},300);
				});
				return;
			}
			var nohost_phones = $("#prepare_ul li:not(.call_disabled) div.prep_phone");
			for(var i=0;i<nohost_phones.length;i++){
				if($(nohost_phones[i]).html().search(/^\d{10,12}$/) == -1){
					zebra_alert("请先输入其他成员电话号码，座机请加区号",function(){
						setTimeout(function(){$(nohost_phones[i]).nextAll("div.prep_edit").click();},300);
					});
					return;
				}
			}
			var lis = [];
			var _phones = $("#prepare_ul div.widget_checker>span.checked").parents("li").find(".prep_phone");
			$.each(_phones,function(i,n){
				if($.trim($(n).text()).search(/^\d{10,12}$/)!=-1){
					lis.push($(n).parent("li"));
				}
			});
			if(lis.length < 3){
				zebra_alert("至少要选择三个有电话的用户才能发起通话");
				return;
			}
			if(lis.length > 10){
				zebra_alert("最多选择十个用户");
				return;
			}
			$.fancybox.close();
			fancylay.block();
			var _data ={};
			var ids = [];
			var names = [];
			var phones = [];
			var urls = [];
			for(var i = lis.length-1;i >= 0;i--){
				var $li = $(lis[i]);
				ids.push($li.attr("data"));
				names.push($li.find(".prep_name").text());
				phones.push($li.find(".prep_phone").text());
				urls.push($li.find(">img").attr("src"));
			}
			_data.action = $("#call_action").val();
			_data.user_ids = ids.join(",");
			_data.userids = ids;
			_data.names = names;
			_data.phones = phones;
			_data.urls = urls;
			_data.linkid = $("#linkid").val();
			//清空数据
			$("#call_selectedlist").undelegate("li","click").empty();
			$("#call_sellist").undelegate("li","click").empty();
			iwk_call.left_data = '';
			iwk_call.data1 = '';
			$("#sel_input").val("");
			$("#call_sel").addClass("loading_wrap").html('<div id="call_loading"><div></div></div>');
			$.post( '' + "inside/apply_call/r:" + Math.round(Math.random() * 1000), _data, function(res) {
				res = JSON.parse(res.match(/{"status.*"}/));
				fancylay.unblock();
				if(res.status == "ok"){
					$("#session_id").val(res.data);
					iwk_call.show_call_status(_data);
				}else{
					zebra_alert(res.message);
				}
			});
			iwk_call.clear_data();
		},
		prepare_call:function(){
			var lis = $("#call_selectedlist li");
			$.fancybox.close();
			var _data ={};
			var li_arr = [];
			for(var i = 0;i < lis.length;i++){
				var $li = $(lis[i]);
				if(i == 0){
					li_arr.push('<li class="call_disabled" data="');
					li_arr.push($li.attr("data")+'">');
					li_arr.push('<div  class="widget_checker disabled">\
						<span class="checked">\
							<input type="checkbox" checked="checked" value="1">\
						</span>\
					</div>');
					li_arr.push('<div class="prep_name">');
					li_arr.push($li.find("span.call_name").text());
					li_arr.push('</div>');
				}else{
					li_arr.push('<li data="');
					li_arr.push($li.attr("data")+'">');
					li_arr.push('<div class="widget_checker ">\
						<span class="checked">\
							<input type="checkbox" checked="checked" value="1">\
						</span>\
					</div>');
					li_arr.push('<div class="call_delete"><img src="');
					li_arr.push('' + "themes/art/imgs/home_right/call_btn_right.png");
					li_arr.push('"></div>');
					li_arr.push('<div class="prep_name">');
					li_arr.push($li.find("span.call_name").text());
					li_arr.push('</div>');
				}
				li_arr.push('<div class="prep_phone">');
				li_arr.push($li.find("span.call_tel").text());
				li_arr.push('</div>');
				li_arr.push('<input class="edit_ipt hide" type="text" placeholder="输入电话号码">');
				li_arr.push('<div class="prep_edit" title="编辑号码"></div>');				
				li_arr.push('<div class="klearboth"></div>');
				li_arr.push('</li>');
			}
			var prepare_ul = $("#prepare_ul");
			prepare_ul.html(li_arr.join(""));
			var _phones = prepare_ul.find("div.prep_phone");
			for(var i = 0;i < _phones.length;i++){
				var $phone = $(_phones[i]);
				if($.trim($phone.html()).search(/^\d{10,12}$/)==-1){
					$phone.addClass("prep_phone_empty").html("请点击编辑输入电话");
					if($phone.prevAll("div.widget_checker").is(".disabled")){
						continue;
					}
					var _check = $phone.prevAll("div.widget_checker");
					_check.find("span").removeClass("checked");
					_check.find("input").prop("checked",false);
				}
			}
			$.fancybox({
	    		modal: true,
	    		//scrolling: "visible",
	    		href: "#call_pop_prepare_win",
	    		helpers: {overlay: {opacity: 0.2}},
	    		padding:0,
	    		beforeLoad: function(){
	    		},
	    		afterShow : function(){
	    			$(".fancybox-inner").css({'overflow':'hidden'});
	    		}
	    	});
			iwk_call.clear_step1_data();
			iwk_call.clear_data();
		},
		prepare_priv:function(){
			var _radio = $("#priv_body input:checked");
			if(_radio.length == 0){
				zebra_alert("请先选择一个私信群组");
				return;
			}
			var data = iwk_call.data2[_radio.val()];
			var li_arr = [];
			
			li_arr.push('<li class="call_disabled" data="');
			li_arr.push(iwk_call._me.id+'">');
			li_arr.push('<div class="widget_checker disabled">\
				<span class="checked">\
					<input type="checkbox" checked="checked" value="1">\
				</span>\
			</div>');
			li_arr.push('<div class="prep_name">');
			li_arr.push(iwk_call._me.fullname+'(主持人)');
			li_arr.push('</div>');
			li_arr.push('<div class="prep_phone">');
			li_arr.push(iwk_call._me.mobile==""?(iwk_call._me.work_mobile==""?iwk_call._me.phone:iwk_call._me.work_mobile):iwk_call._me.mobile);
			li_arr.push('</div>');
			li_arr.push('<input class="edit_ipt hide" type="text" placeholder="输入电话号码">');
			li_arr.push('<div class="prep_edit" title="编辑号码"></div>');
			li_arr.push('<div class="klearboth"></div>');
			li_arr.push('</li>');
			
			for(var i in data.prv_user_info){
				if(iwk_call._me.id == data.prv_user_info[i].id){
					continue;
				}
				
				li_arr.push('<li data="');
				li_arr.push( data.prv_user_info[i].id+'">');
				li_arr.push('<div class="widget_checker ">\
					<span class="checked">\
						<input type="checkbox" checked="checked" value="1">\
					</span>\
				</div>');
				li_arr.push('<div class="call_delete"><img src="');
				li_arr.push('' + "themes/art/imgs/home_right/call_btn_right.png");
				li_arr.push('"></div>');
				li_arr.push('<div class="prep_name">');
				li_arr.push(data.prv_user_info[i].fullname);
				li_arr.push('</div>');
				li_arr.push('<div class="prep_phone">');
				li_arr.push(data.prv_user_info[i].mobile == ""?(data.prv_user_info[i].work_mobile==""?data.prv_user_info[i].phone:data.prv_user_info[i].work_mobile):data.prv_user_info[i].mobile);
				li_arr.push('</div>');
				li_arr.push('<input class="edit_ipt hide" type="text" placeholder="输入电话号码">');
				li_arr.push('<div class="prep_edit" title="编辑号码"></div>');
				li_arr.push('<div class="klearboth"></div>');
				li_arr.push('</li>');
			}
			var prepare_ul = $("#prepare_ul");
			prepare_ul.html(li_arr.join(""));
			var _phones = prepare_ul.find("div.prep_phone");
			for(var i = 0;i < _phones.length;i++){
				var $phone = $(_phones[i]);
				if($.trim($phone.html()).search(/^\d{10,12}$/)==-1){
					$phone.addClass("prep_phone_empty").html("请点击编辑输入电话");
					if($phone.prevAll("div.widget_checker").is(".disabled")){
						continue;
					}
					var _check = $phone.prevAll("div.widget_checker");
					_check.find("span").removeClass("checked");
					_check.find("input").prop("checked",false);
				}
			}
			$.fancybox({
	    		modal: true,
	    		//scrolling: "visible",
	    		href: "#call_pop_prepare_win",
	    		helpers: {overlay: {opacity: 0.2}},
	    		padding:0,
	    		beforeLoad: function(){
	    		}
	    	});
			$("#linkid").val(data.post_linkid);
			iwk_call.clear_step1_data();
			iwk_call.clear_data();
		},
		//私信中发起通话
		prepare_priv_list : function(){
			$("#finish_list_loading").show();
			$("#finish_userpick_ul").html("");
			$("#priv_list_loading").show();
			$("#prepare_userpick_ul").html("");
			$("#priv_list_footer").hide();
			$("#finish_list_footer").hide();
			$("#call_action").val("ok");
			var $lists = $("#prv_group_user_list div.irbb_line");
			var li_arr = [];
			for(var i = 0;i < $lists.length;i++){
				var $div = $($lists[i]);
				if($div.find("div.prv_group_user").attr("data") == $("#prv_user_id").val()){
					li_arr.push('<li class="call_disabled" data="');
					li_arr.push( $div.find("div.prv_group_user").attr("data")+'">');
					li_arr.push('<div class="widget_checker disabled">\
						<span class="checked">\
							<input type="checkbox" checked="checked" value="1">\
						</span>\
					</div>');
					li_arr.push('<div class="prep_name">');
					li_arr.push($div.find("div.prv_group_user>span:first").html()+'(主持人)');
					li_arr.push('</div>');
					li_arr.push('<div class="prep_phone">');
					li_arr.push($div.find("input.phone_num").val());
					li_arr.push('</div>');
					li_arr.push('<input class="edit_ipt hide" type="text" placeholder="输入电话号码">');
					li_arr.push('<div class="prep_edit" title="编辑号码"></div>');
					li_arr.push('<div class="klearboth"></div>');
					li_arr.push('</li>');
					break;
				}
			}
			for(var i = 0;i < $lists.length;i++){
				var $div = $($lists[i]);
				if($div.find("div.prv_group_user").attr("data") == $("#prv_user_id").val()){
					continue;
				}
				li_arr.push('<li data="');
				li_arr.push( $div.find("div.prv_group_user").attr("data")+'">');
				li_arr.push('<div class="widget_checker ">\
					<span class="checked">\
						<input type="checkbox" checked="checked" value="1">\
					</span>\
				</div>');
				li_arr.push('<div class="call_delete"><img src="');
				li_arr.push('' + "themes/art/imgs/home_right/call_btn_right.png");
				li_arr.push('"></div>');
				li_arr.push('<div class="prep_name">');
				li_arr.push($div.find("div.prv_group_user>span:first").html());
				li_arr.push('</div>');
				li_arr.push('<div class="prep_phone">');
				li_arr.push($div.find("input.phone_num").val());
				li_arr.push('</div>');
				li_arr.push('<input class="edit_ipt hide" type="text" placeholder="输入电话号码">');
				li_arr.push('<div class="prep_edit" title="编辑号码"></div>');
				li_arr.push('<div class="klearboth"></div>');
				li_arr.push('</li>');
			}
			var prepare_ul = $("#prepare_ul");
			prepare_ul.html(li_arr.join(""));
			var _phones = prepare_ul.find("div.prep_phone");
			for(var i = 0;i < _phones.length;i++){
				var $phone = $(_phones[i]);
				if($.trim($phone.html()).search(/^\d{10,12}$/)==-1){
					$phone.addClass("prep_phone_empty").html("请点击编辑输入电话");
					if($phone.prevAll("div.widget_checker").is(".disabled")){
						continue;
					}
					var _check = $phone.prevAll("div.widget_checker");
					_check.find("span").removeClass("checked");
					_check.find("input").prop("checked",false);
				}
			}
			$.fancybox({
	    		modal: true,
	    		//scrolling: "visible",
	    		href: "#call_pop_prepare_win",
	    		helpers: {overlay: {opacity: 0.2}},
	    		padding:0,
	    		beforeLoad: function(){
	    		}
	    	});
			$("#linkid").val($("#priv_link_id").val());
		},
		close_step2:function(){
			$.fancybox.close();
			iwk_call.clear_all_data();
			$("#call_pop_prepare_wrap").animate({left:"0"},300);
		},
		clear_data:function(){
			iwk_call.data1 = "";
			iwk_call.data2 = "";
			iwk_call.data3 = "";
		},
		sending:0,
		confirm_add:function(){
			var users = $("#add_external_input").userpicker("getData").user;
			$("#add_external_input").remove();
			$("#confirm_add").remove();
			var li_arr = [];
			$.each(users,function(i,n){
				var obj = iwk_call.data3[n];
				li_arr.push('<li data="');
				li_arr.push( obj.id+'">');
				li_arr.push('<div class="widget_checker ">\
					<span class="checked">\
						<input type="checkbox" checked="checked" value="1">\
					</span>\
				</div>');
				li_arr.push('<div class="prep_name">');
				li_arr.push(obj.fullname);
				li_arr.push('</div>');
				li_arr.push('<div class="prep_phone">');
				li_arr.push(obj.mobile);
				li_arr.push('</div>');
				li_arr.push('<input class="edit_ipt hide" type="text" placeholder="输入电话号码">');
				li_arr.push('<div class="prep_edit" title="编辑号码"></div>');
				li_arr.push('<div class="klearboth"></div>');
				li_arr.push('</li>');
			});
			var prepare_ul = $("#prepare_ul");
			prepare_ul.append(li_arr.join(""));
		},
		show_call_status:function(_data){
			$.fancybox({
	    		modal: true,
	    		//scrolling: "visible",
	    		href: "#call_finish_wrap",
	    		helpers: {overlay: {opacity: 0.2}},
	    		padding:0,
	    		beforeLoad: function(){
	    		}
	    	});
			var _arrs = [];
			var _li_cls = '';
			for(var i = 0;i <_data.phones.length;i++){
				if(i==0){
					_li_cls="li_host";
				}else{
					_li_cls = '';
				}
				_arrs.push('<li data="');
				_arrs.push(_data.userids[i]);
				_arrs.push('" class="');
				_arrs.push(_li_cls);
				_arrs.push('"><a><span class="call_name">');
				_arrs.push(_data.names[i]);
				_arrs.push('</span><span class="call_tel">');
				_arrs.push(_data.phones[i]);
				_arrs.push('</span>')
				_arrs.push('<span id="call_status');
				_arrs.push(_data.userids[i]);
				if(i == 0){
					_arrs.push('" class="status_bell"></span>');
					_arrs.push('<span id="status_label');
					_arrs.push(_data.userids[i]);
					_arrs.push('" class="status_label">呼叫中</span>');
				}else{
					_arrs.push('"></span>');
					_arrs.push('<span id="status_label');
					_arrs.push(_data.userids[i]);
					_arrs.push('" class="status_label"></span>');
				}
				if(i >0){
					_arrs.push('<span data="');
					_arrs.push(_data.userids[i]);
					_arrs.push('" id="call_action_wrap');
					_arrs.push(_data.userids[i]);
					_arrs.push('" class="call_action_wrap">');
					_arrs.push('<span id="call_action');
					_arrs.push(_data.userids[i]);
					_arrs.push('"></span>');
					_arrs.push('<span id="action_label');
					_arrs.push(_data.userids[i]);
					_arrs.push('" class="action_label"></span>\
						</span>');
				}
				_arrs.push("</a></li>");
			}
			$("#call_status_list").html(_arrs.join(""));
			iwk_call.get_status();
		},
		recall:function($this){
			var _data = {};
			_data.action = "recall";
			_data.session_id = $("#session_id").val();
			_data.userid = $this.attr("data");
			_data.phones = $.trim($this.prevAll(".call_tel").html());
			
			$this.removeClass().prev().html("请求中");
			$this.find(".action_label").html("");
			
			iwk_call.recallings.push(_data.userid);
			$.post( '' + "inside/apply_call/r:" + Math.round(Math.random() * 1000), _data, function(res) {
				if(res.status == "ok"){
				}else{
					zebra_alert(res.message);
					$this.find(":first").addClass("call_action action_recall").next().html("重拨");
					$this.prev().show().prev().show();
				}
			},'json');
		},
		kick:function($this){
			var _data = {};
			_data.action = "kick";
			_data.session_id = $("#session_id").val();
			_data.userid = $this.attr("data");
			
			$this.removeClass().prev().html("请求中");
			$this.find(".action_label").html("");
			
			iwk_call.kicking.push(_data.userid);
			$.post( '' + "inside/apply_call/r:" + Math.round(Math.random() * 1000), _data, function(res) {
				if(res.status == "ok"){

				}else{
					zebra_alert(res.message);
					$this.find(":first").addClass("call_action action_hang").next().html("挂断");
					$this.prev().show().prev().show();
				}
			},'json');
		},
		status_timeout:'',
		get_status:function(){
			var _data = {};
			_data.action = "get_state";
			_data.session_id = $("#session_id").val();
			
			$.post( '' + "inside/apply_call/r:" + Math.round(Math.random() * 1000), _data, function(res) {
				if(res.talk_state == 3){
					$.fancybox.close();
					$.fancybox({
			    		modal: true,
			    		//scrolling: "visible",
			    		href: "#call_pop_prepare_win",
			    		helpers: {overlay: {opacity: 0.2}},
			    		padding:0,
			    		beforeLoad: function(){
			    		}
			    	});
					zebra_alert("主持人未接通，请重新发起通话");
					return;
				}else if(res.talk_state == 0){
					iwk_call.end_call();
					return;
				}else if(res.talk_state == 2){
					$("#end_call").show();
					$("#continue_invite").show();
					
					$.each(res.data,function(key,value){
						if($.inArray(""+value.user_id,iwk_call.recallings) != -1){
							if(value.call_state != 1 && value.call_state != 2){
								return;
							}else{
								iwk_call.recallings.splice($.inArray(value.user_id,iwk_call.recallings),1);
							}
						}
						if($.inArray(""+value.user_id,iwk_call.kicking) != -1){
							if(value.call_state != 3 && value.call_state != 4){
								return;
							}else{
								iwk_call.kicking.splice($.inArray(value.user_id,iwk_call.kicking),1);
							}
						}
						switch(value.call_state){
						case 1:
							$("#call_status"+value.user_id).removeClass().addClass('status_bell').show();
							$("#status_label"+value.user_id).html("呼叫中").show();
							$("#recall"+value.user_id).hide();
							break;
						case 2:
							$("#call_action_wrap"+value.user_id).removeClass().addClass("call_action_wrap hang_status").show();
							$("#call_status"+value.user_id).removeClass().addClass('status_answer').show();
							$("#status_label"+value.user_id).html("通话中").show();
							$("#call_action"+value.user_id).removeClass().addClass('call_action action_hang').show();
							$("#action_label"+value.user_id).html("挂断").show();
							$("#recall"+value.user_id).hide();
							break;
						case 4:
							$("#call_action_wrap"+value.user_id).removeClass().addClass("call_action_wrap recall_status").show();
							$("#call_status"+value.user_id).removeClass().addClass('status_timeout').show();
							$("#status_label"+value.user_id).html("未接").show();
							$("#call_action"+value.user_id).removeClass().addClass('call_action action_recall').show();
							$("#action_label"+value.user_id).html("重拨").show();
							$("#recall"+value.user_id).show();
							break;
						case 3:
							$("#call_action_wrap"+value.user_id).removeClass().addClass("call_action_wrap recall_status").show();
							$("#call_status"+value.user_id).removeClass().addClass('status_hangup').show();
							$("#status_label"+value.user_id).html("已挂断").show();
							$("#call_action"+value.user_id).removeClass().addClass('call_action action_recall').show();
							$("#action_label"+value.user_id).html("重拨").show();
							break;
						}
					});
				}
				iwk_call.status_timeout = setTimeout('iwk_call.get_status()',3000);
			},'json');
		},
		end_sending:'',
		end_call:function(){
			clearTimeout(iwk_call.status_timeout);
			$("#add_continue_input").remove();
			$("#confirm_continue").remove();
			iwk_call.data3 = '';
			var _data = {};
			_data.action = "end_call";
			_data.session_id = $("#session_id").val();
			if(iwk_call.end_sending){
				$("a[class^=ZebraDialog_Button]").click();
				zebra_alert("请求发送中，请稍等");
				return;
			}
			iwk_call.end_sending = "1";
			$.post( '' + "inside/apply_call/r:" + Math.round(Math.random() * 1000), _data, function(res) {
				clearTimeout(iwk_call.status_timeout);
				if(res && res.status=='ok'){
					iwk_call.status_timeout="";
					$("a[class^=ZebraDialog_Button]").click();
					zebra_auto("您已结束电话会议");
				}else{
					iwk_call.status_timeout = setTimeout('iwk_call.get_status()',3000);
					$("a[class^=ZebraDialog_Button]").click();
					zebra_alert(res.message);
				}
				$("#call_finish_wide").css({left:0});
				iwk_call.end_sending = "";
				$("#session_id").val("");
				$("#call_status_list").empty();
				$.fancybox.close();
			},'json');
			iwk_call.clear_all_data();
		},
		continue_invite : function(){
			$("#call_finish_wide").animate({left:-535},300);
			
			//取之前界面已有的user的id，用于过滤掉
			var _lis = $("#call_status_list li");
			var userids =[];
			var me_id;
			var _data = iwk_call.data0;
			var _ul = [];
			var ul_right=[];
			var _host = [];
			for(var i = 0;i < _lis.length;i++){
				userids.push($(_lis[i]).attr("data"));
				$phone = $.trim($(_lis[i]).find('.call_tel').text()).search(/^\d{10,12}$/)==-1?'':$.trim($(_lis[i]).find('.call_tel').text());
				if($(_lis[i]).is(".li_host")){
					me_id = $.trim($(_lis[i]).attr("data"));
					_host.push('<li class="is_host call_disabled" data="');
					_host.push($.trim($(_lis[i]).attr("data"))+'">');
					_host.push('<a><span class="call_name">');
					_host.push($.trim($(_lis[i]).find('.call_name').text()));
					_host.push('</span>');
					_host.push('<span class="call_tel">');
					_host.push($phone);
					_host.push('</span></a>');
					_host.push('</li>');
					continue;
				}
				ul_right.push('<li data="');
				ul_right.push($.trim($(_lis[i]).attr("data")));
				ul_right.push('" class="nohost call_disabled" >');
				ul_right.push('<a><span class="call_name">');
				ul_right.push($.trim($(_lis[i]).find('.call_name').text()));
				ul_right.push('</span>');
				ul_right.push('<span class="call_tel">');
				ul_right.push($phone);
				ul_right.push('</span></a>');
				ul_right.push('</li>');
			}
			var useridstr = ","+userids.join(",")+",";
			if(!iwk_call.data0){
				var _data ={
					    "text": "",
					    "type": "org",
					    "group": [],
					    "org": [],
					    "is_private_group": true,
					    "user_scope_group": [],
					    "scope_group": [],
					    "with_special_group": true,
					    "show_group": true,
					    "show_org": true,
					    "all":true
					};
				$.post( '' + "ajax/pagi_userpicker/r:" + Math.round(Math.random() * 1000), _data, function(res) {
					res.data.sort(function(a,b){
						return a.name.localeCompare(b.name);
					});
					for(var i = 0;i < res.data.length;i++){
						res.data[i].mobile = res.data[i].mobile == ""?(res.data[i].work_mobile==""?res.data[i].phone:res.data[i].work_mobile):res.data[i].mobile;
					}
					iwk_call.data0 = res.data;
					var _data = iwk_call.data0;
					var _ul = [];
					for(var i = 0;i < _data.length;i++){
						if(useridstr.search(","+$.trim(_data[i].id)+",")!=-1){
							continue;
						}
						if(_data[i].type == "user"){
							_ul.push('<li data="');
							_ul.push(_data[i].id);
							_ul.push('" class="nohost call_abled" >');
							_ul.push('<a><span class="call_name">');
							_ul.push(_data[i].name);
							_ul.push('</span>');
							_ul.push('<span class="call_tel">');
							_ul.push(_data[i].mobile);
							_ul.push('</span></a>');
							_ul.push('</li>');
						}
					}
					$("#finish_userpick_sellist").html(_ul.join("")).show();
					$("#finish_userpick_sel").removeClass("loading_wrap");
					$("#finish_userpick_selectedlist").html(_host.join("") + ul_right.join("")).show();
					$("#finish_userpick_count").html( _lis.length);
					$("#finish_list_loading").hide();
					$("#finish_list_footer").show();
					iwk_call.data4 = $("#finish_userpick_sellist").html() + $("#finish_userpick_selectedlist").html();
				},'json');
			}else{
				var _data = iwk_call.data0;
				var _ul = [];
				for(var i = 0;i < _data.length;i++){
					if(useridstr.search(","+$.trim(_data[i].id)+",")!=-1){
						continue;
					}
					if(_data[i].type == "user"){
						_ul.push('<li data="');
						_ul.push(_data[i].id);
						_ul.push('" class="nohost call_abled" >');
						_ul.push('<a><span class="call_name">');
						_ul.push(_data[i].name);
						_ul.push('</span>');
						_ul.push('<span class="call_tel">');
						_ul.push(_data[i].mobile);
						_ul.push('</span></a>');
						_ul.push('</li>');
					}
				}
				$("#finish_userpick_sellist").html(_ul.join("")).show();
				$("#finish_userpick_sel").removeClass("loading_wrap");
				$("#finish_userpick_selectedlist").html(_host.join("") + ul_right.join("")).show();
				$("#finish_userpick_count").html( _lis.length);
				$("#finish_list_loading").hide();
				//$("#finish_list_footer").show();
				iwk_call.data4 = $("#finish_userpick_sellist").html() + $("#finish_userpick_selectedlist").html();
			}
		},
		confirm_add_calling : function(){
			var users = $("#add_continue_input").userpicker("getData").user;
			var invite_users = [];
			var invite_phones = [];
			$("#add_continue_input").remove();
			$("#confirm_continue").next().remove();
			$("#confirm_continue").remove();
			var li_arr = [];
			$.each(users,function(i,n){
				var obj = iwk_call.data3[n];
				li_arr.push('<li><a><span class="call_name">');
				li_arr.push(obj.fullname);
				li_arr.push('</span><span class="call_tel">');
				li_arr.push(obj.mobile);
				li_arr.push('</span>')
				li_arr.push('<span id="call_status');
				li_arr.push(obj.id);
				li_arr.push('"></span>');
				li_arr.push('<span id="status_label');
				li_arr.push(obj.id);
				li_arr.push('" class="status_label"></span>');
				li_arr.push('<span class="call_action_wrap">\
						<span id="call_action');
				li_arr.push(obj.id);
				li_arr.push('"></span>');
				li_arr.push('<span id="action_label');
				li_arr.push(obj.id);
				li_arr.push('" class="action_label"></span>\
					</span>');
				li_arr.push("</a></li>");
				if($.trim(obj.mobile).search(/^\d{10,12}$/)!=-1){
					invite_users.push(obj.id);
					invite_phones.push($.trim(obj.mobile));
				}
			});
			var prepare_ul = $("#call_status_list");
			prepare_ul.append(li_arr.join(""));
			var _data = {};
			_data.action = 'continue_invite';
			_data.users = invite_users;
			_data.phones = invite_phones;
			_data.session_id = $("#session_id").val();
			$.post( '' + "inside/apply_call/r:" + Math.round(Math.random() * 1000), _data, function(res) {
				
			},'json');
		},
		call_action : function(){
			var $this = $(this);
			var $action = $this.find(".call_action");
			if($action.is(".action_recall")){
				iwk_call.recall($this);
			}else if($action.is(".action_hang")){
				iwk_call.kick($this);
			}
		},
		add_prepare_user_new :function(){
			$("#call_pop_prepare_wrap").animate({left:"-535"},300);
			
			//取之前界面已有的user的id，用于过滤掉
			var _lis = $("#prepare_ul").find("li");
			var userids =[];
			var me_id;
			var _data = iwk_call.data0;
			var _ul = [];
			var ul_right=[];
			var _host = [];
			//_ul.push('<ul id="userpick_sellist" class="call_ul">');
			for(var i = 0;i < _lis.length;i++){
				userids.push($.trim($(_lis[i]).attr("data")));
				$phone = $.trim($(_lis[i]).find('.prep_phone').text()).search(/^\d{10,12}$/)==-1?'':$.trim($(_lis[i]).find('.prep_phone').text());
				if($(_lis[i]).is(".call_disabled")){
					me_id = $.trim($(_lis[i]).attr("data"));
					_host.push('<li class=" is_host call_disabled" data="');
					_host.push($.trim($(_lis[i]).attr("data"))+'">');
					_host.push('<a><span class="call_name">');
					_host.push($.trim($(_lis[i]).find('.prep_name').text()));
					_host.push('</span>');
					_host.push('<span class="call_tel">');
					_host.push($phone);
					_host.push('</span></a>');
					_host.push('</li>');
					continue;
				}
				ul_right.push('<li data="');
				ul_right.push($.trim($(_lis[i]).attr("data")));
				ul_right.push('" class="nohost call_abled" >');
				ul_right.push('<a><span class="call_name">');
				ul_right.push($.trim($(_lis[i]).find('.prep_name').text()));
				ul_right.push('</span>');
				ul_right.push('<span class="call_tel">');
				ul_right.push($phone);
				ul_right.push('</span></a>');
				ul_right.push('</li>');
			}
			var useridstr = ","+userids.join(",")+",";
			if(!iwk_call.data0){
				var _data ={
					    "text": "",
					    "type": "org",
					    "group": [],
					    "org": [],
					    "is_private_group": true,
					    "user_scope_group": [],
					    "scope_group": [],
					    "with_special_group": true,
					    "show_group": true,
					    "show_org": true,
					    "all":true
					};
				$.post( '' + "ajax/pagi_userpicker/r:" + Math.round(Math.random() * 1000), _data, function(res) {
					res.data.sort(function(a,b){
						return a.name.localeCompare(b.name);
					});
					for(var i = 0;i < res.data.length;i++){
						res.data[i].mobile = res.data[i].mobile == ""?(res.data[i].work_mobile==""?res.data[i].phone:res.data[i].work_mobile):res.data[i].mobile;
					}
					iwk_call.data0 = res.data;
					var _data = iwk_call.data0;
					for(var i = 0;i < _data.length;i++){
						if(useridstr.search(","+$.trim(_data[i].id)+",")!=-1){
							continue;
						}
						if(_data[i].type == "user"){
							_ul.push('<li data="');
							_ul.push(_data[i].id);
							_ul.push('" class="nohost call_abled" >');
							_ul.push('<a><span class="call_name">');
							_ul.push(_data[i].name);
							_ul.push('</span>');
							_ul.push('<span class="call_tel">');
							_ul.push(_data[i].mobile);
							_ul.push('</span></a>');
							_ul.push('</li>');
						}
					}
					//_ul.push('</ul>');
					//iwk_call.data4 = _ul.join("");
					//$("#priv_list_loading").hide();
					$("#userpick_sellist").html(_ul.join("")).show();
					$("#prepare_userpick_sel").removeClass("loading_wrap");
					$("#prepare_userpick_selectedlist").html(_host.join("") + ul_right.join("")).show();
					$("#userpick_count").html( _lis.length);
					$("#priv_list_footer").show();
					iwk_call.data4 = $("#userpick_sellist").html()+$("#prepare_userpick_selectedlist").html();
				},'json');
			}else{
			for(var i = 0;i < _data.length;i++){	
				if(useridstr.search(","+$.trim(_data[i].id)+",")!=-1){					
					continue;
				}
				if(_data[i].type == "user"){
					_ul.push('<li data="');
					_ul.push(_data[i].id);
					_ul.push('" class="nohost call_abled" >');
					_ul.push('<a><span class="call_name">');
					_ul.push(_data[i].name);
					_ul.push('</span>');
					_ul.push('<span class="call_tel">');
					_ul.push(_data[i].mobile);
					_ul.push('</span></a>');
					_ul.push('</li>');
				}
			}
			//_ul.push('</ul>');
			//iwk_call.data4 = _ul.join("");
			//$("#prepare_userpick_sel").find(".call_loading").hide();
			$("#userpick_sellist").html(_ul.join("")).show();
			$("#prepare_userpick_sel").removeClass("loading_wrap");
			//$("#prepare_userpick_sel").removeClass("call_loading");
			$("#prepare_userpick_selectedlist").html(_host.join("") + ul_right.join("")).show();
			$("#userpick_count").html( _lis.length);
			$("#priv_list_footer").show();
			iwk_call.data4 = $("#userpick_sellist").html()+$("#prepare_userpick_selectedlist").html();
			}
		},
		add_prepare_user : function(){
			$("#call_pop_prepare_wrap").animate({left:"-535"},300);
			
			//取之前界面已有的user的id，用于过滤掉
			var _lis = $("#prepare_ul").find("li");
			var userids =[];
			for(var i = 0;i < _lis.length;i++){
				userids.push($.trim($(_lis[i]).attr("data")));
			}
			var useridstr = ","+userids.join(",")+",";
			if(!iwk_call.data0){
				var _data ={
					    "text": "",
					    "type": "org",
					    "group": [],
					    "org": [],
					    "is_private_group": true,
					    "user_scope_group": [],
					    "scope_group": [],
					    "with_special_group": true,
					    "show_group": true,
					    "show_org": true,
					    "all":true
					};
				$.post( '' + "ajax/pagi_userpicker/r:" + Math.round(Math.random() * 1000), _data, function(res) {
					res.data.sort(function(a,b){
						return a.name.localeCompare(b.name);
					});
					for(var i = 0;i < res.data.length;i++){
						res.data[i].mobile = res.data[i].mobile == ""?(res.data[i].work_mobile==""?res.data[i].phone:res.data[i].work_mobile):res.data[i].mobile;
					}
					iwk_call.data0 = res.data;
					var _data = iwk_call.data0;
					var _ul = [];
					for(var i = 0;i < _data.length;i++){
						if(useridstr.search(","+$.trim(_data[i].id)+",")!=-1){
							continue;
						}
						if(_data[i].type == "user"){
							_ul.push('<li data="');
							_ul.push(_data[i].id);
							_ul.push('">');
							_ul.push('<div class="widget_checker ">\
									<span class="">\
									<input type="checkbox" value="1">	\
									</span>\
							</div>');
							_ul.push('<div class="prep_name">');
							_ul.push(_data[i].name);
							_ul.push('</div>');
							_ul.push('<div class="prep_phone">');
							_ul.push(_data[i].mobile);
							_ul.push('</div>');
							_ul.push('<input class="edit_ipt hide" type="text" placeholder="输入电话号码">');
							_ul.push('<div class="prep_edit" titl="编辑号码"></div><div class="klearboth"></div>');
							_ul.push('</li>');
						}
					}
					iwk_call.data4 = _ul.join("");
					$("#priv_list_loading").hide();
					$("#prepare_userpick_ul").html(_ul.join("")).show();
					$("#priv_list_footer").show();
					var _phones = $("#prepare_userpick_ul").find("div.prep_phone");
					for(var i = 0;i < _phones.length;i++){
						var $phone = $(_phones[i]);
						if($.trim($phone.html()).search(/^\d{10,12}$/)==-1){
							$phone.addClass("prep_phone_empty").html("请点击编辑输入电话");
						}
					}
				},'json');
			}
			var _data = iwk_call.data0;
			var _ul = [];
			for(var i = 0;i < _data.length;i++){
				if(useridstr.search(","+$.trim(_data[i].id)+",")!=-1){
					continue;
				}
				if(_data[i].type == "user"){
					_ul.push('<li data="');
					_ul.push(_data[i].id);
					_ul.push('">');
					_ul.push('<div class="widget_checker ">\
							<span class="">\
							<input type="checkbox" value="1">	\
							</span>\
					</div>');
					_ul.push('<div class="prep_name">');
					_ul.push(_data[i].name);
					_ul.push('</div>');
					_ul.push('<div class="prep_phone">');
					_ul.push(_data[i].mobile);
					_ul.push('</div>');
					_ul.push('<input class="edit_ipt hide" type="text" placeholder="输入电话号码">');
					_ul.push('<div class="prep_edit" titl="编辑号码"></div><div class="klearboth"></div>');
					_ul.push('</li>');
				}
			}
			iwk_call.data4 = _ul.join("");
			$("#prepare_userpick_ul").html(_ul.join(""));
			var _phones = $("#prepare_userpick_ul").find("div.prep_phone");
			for(var i = 0;i < _phones.length;i++){
				var $phone = $(_phones[i]);
				if($.trim($phone.html()).search(/^\d{10,12}$/)==-1){
					$phone.addClass("prep_phone_empty").html("请点击编辑输入电话");
				}
			}
		},
		cancel_prepare_user : function(){
			$("#call_pop_prepare_wrap").animate({left:"0"},300);
			$(".call_select_check").find("span").removeClass("checked");
			$(".call_select_check").find("input").prop("checked",false);
		},
		select_userpicker : function(){
			var _checker = $(this).find(".widget_checker");
			if(_checker.find("span").is(".checked")){
				_checker.find("span").removeClass("checked");
				_checker.find("input").prop("checked",false);
			}else{
				_checker.find("span").addClass("checked");
				_checker.find("input").prop("checked",true);
			}
		},
		confirm_prepare_user : function(){
			//var _ul = $(iwk_call.data4);
			var _lis = $("#prepare_userpick_selectedlist li");
			//var _lis = _ul.find("span.checked").parents("li");
			var _vals = [];
			for(var i = 0;i < _lis.length;i++){
				var $li = $(_lis[i]);
				if(i == 0){
					_vals.push('<li class="call_disabled" data="');
					_vals.push($li.attr("data")+'">');
					_vals.push('<div  class="widget_checker disabled">\
						<span class="checked">\
							<input type="checkbox" checked="checked" value="1">\
						</span>\
					</div>');
					_vals.push('<div class="prep_name">');
					_vals.push($li.find("span.call_name").text());
					_vals.push('</div>');
				}else{
					_vals.push('<li data="');
					_vals.push($li.attr("data")+'">');
					_vals.push('<div class="widget_checker ">\
						<span class="checked">\
							<input type="checkbox" checked="checked" value="1">\
						</span>\
					</div>');
					_vals.push('<div class="call_delete"><img src="');
					_vals.push('' + "themes/art/imgs/home_right/call_btn_right.png");
					_vals.push('"></div>');
					_vals.push('<div class="prep_name">');
					_vals.push($li.find("span.call_name").text());
					_vals.push('</div>');
				}
				_vals.push('<div class="prep_phone">');
				_vals.push($li.find("span.call_tel").text());
				_vals.push('</div>');
				_vals.push('<input class="edit_ipt hide" type="text" placeholder="输入电话号码">');
				_vals.push('<div class="prep_edit" title="编辑号码"></div>');				
				_vals.push('<div class="klearboth"></div>');
				_vals.push('</li>');
			}
			$("#prepare_ul").empty().append(_vals.join(""));
			var _phones = $("#prepare_ul").find("div.prep_phone");
			for(var i = 0;i < _phones.length;i++){
				var $phone = $(_phones[i]);
				if($.trim($phone.html()).search(/^\d{10,12}$/)==-1){
					$phone.addClass("prep_phone_empty").html("请点击编辑输入电话");
					if($phone.prevAll("div.widget_checker").is(".disabled")){
						continue;
					}
					var _check = $phone.prevAll("div.widget_checker");
					_check.find("span").removeClass("checked");
					_check.find("input").prop("checked",false);
				}
			}
			$("#call_pop_prepare_wrap").animate({left:"0"},300);
		},
		cancel_finish_user : function(){
			$("#call_finish_wide").animate({left:"0"},300);
		},
		confirm_finish_user : function(){
			//var _ul = $(iwk_call.data4);
			//var _lis = _ul.find("span.checked").parents("li");
			var _lis = $("#finish_userpick_selectedlist li.call_abled");
			var _arrs = [];
			
			var _data = {};
			_data.action ="continue_invite";
			_data.users = [];
			_data.phones = [];
			
			for(var i = 0;i < _lis.length;i++){
				var $li = $(_lis[i]);
				_arrs.push('<li data="');
				_arrs.push($li.attr("data"));
				_arrs.push('"><a><span class="call_name">');
				_arrs.push($li.find("span.call_name").html());
				_arrs.push('</span><span class="call_tel">');
				_arrs.push($li.find("span.call_tel").html());
				_arrs.push('</span>')
				_arrs.push('<span id="call_status');
				_arrs.push($li.attr("data"));
				_arrs.push('"></span>');
				_arrs.push('<span id="status_label');
				_arrs.push($li.attr("data"));
				_arrs.push('" class="status_label"></span>');
				_arrs.push('<span data="');
				_arrs.push($li.attr("data"));
				_arrs.push('" class="call_action_wrap" id="call_action_wrap');
				_arrs.push($li.attr("data"));
				_arrs.push('">');
				_arrs.push('<span id="call_action');
				_arrs.push($li.attr("data"));
				_arrs.push('"></span>');
				_arrs.push('<span id="action_label');
				_arrs.push($li.attr("data"));
				_arrs.push('" class="action_label"></span>\
					</span>');
				_arrs.push("</a></li>");
				_data.users.push($li.attr("data"));
				_data.phones.push($li.find("span.call_tel").html());
			}
			$("#call_status_list").append(_arrs.join(""));
			$("#call_finish_wide").animate({left:"0"},300);

			_data.session_id = $("#session_id").val();
			$.post( '' + "inside/apply_call/r:" + Math.round(Math.random() * 1000), _data, function(res) {
				
			},'json');
		},
		select_prepare_all : function(_this,_id){
			var $this = $(_this);
			var _ul = $("#"+_id);
			if($this.find("span").is(".checked")){
				$this.find("span").removeClass("checked");
				$this.find("input").prop("checked",false);
				var _checks = _ul.find("div.widget_checker");
				for(var i = 0;i < _checks.length;i++){
					$check = $(_checks[i]);
					if($check.find("span").is(".checked")){
						$check.click();
					}
				}
			}else{
				$this.find("span").addClass("checked");
				$this.find("input").prop("checked",true);
				var _checks = _ul.find("div.widget_checker");
				for(var i = 0;i < _checks.length;i++){
					$check = $(_checks[i]);
					if(!$check.find("span").is(".checked")){
						$check.click();
					}
				}
			}
		},
		select_all : function(_this,_id){
			var $this = $(_this);
			var _ul = $("#"+_id);
			if($this.find("span").is(".checked")){
				$this.find("span").removeClass("checked");
				$this.find("input").prop("checked",false);
				var _checks = _ul.find("div.widget_checker");
				for(var i = 0;i < _checks.length;i++){
					$check = $(_checks[i]);
					if($check.find("span").is(".checked")){
						$check.click();
					}
				}
			}else{
				$this.find("span").addClass("checked");
				$this.find("input").prop("checked",true);
				var _checks = _ul.find("div.widget_checker");
				for(var i = 0;i < _checks.length;i++){
					$check = $(_checks[i]);
					if(!$check.find("span").is(".checked") && $check.nextAll("div.prep_phone").html().search(/^\d{10,12}$/)!=-1){
						$check.click();
					}
				}
			}
		},
		select_search : function(_this,_ul){
			var _val = $.trim($(_this).val());
			var lis = $(iwk_call.data4);
			var $li;
			var _html = [];
			if(_val == ""){
				for(var i = 0;i < lis.length;i++){
					_html.push(lis[i].outerHTML);
				}
				$("#"+_ul).html(_html.join(""));
				return;
			}
			for(var i = 0;i < lis.length;i++){
				$li = $(lis[i]);
				if($li.find("div.prep_name").html().search(_val)!=-1 || $li.find("div.prep_phone").html().search(_val)!=-1){
					_html.push(lis[i].outerHTML);
				}
			}
			$("#"+_ul).html(_html.join(""));
		},
		prepare_ul_check : function(_this){
			var $lis = $(iwk_call.data4);
			var _arr = [];
			var $this = $(_this);
			for(var i = 0;i < $lis.length;i++){
				var $li = $($lis[i]);
				if($li.attr("data") == $this.parent().attr("data")){
					if($this.find("span:first").is(".checked")){
						$li.find("div.widget_checker>span").removeClass("checked");
						$li.find("div.widget_checker input").prop("checked",false);
					}else{
						$li.find("div.widget_checker>span").addClass("checked");
						$li.find("div.widget_checker input").prop("checked",true);
					}
				}
				_arr.push($li.get(0).outerHTML);
			}
			iwk_call.data4 = _arr.join("");
			
			iwk_widget.checkbox_click(_this);
		},
		finish_ul_check : function(_this){
			var $this = $(_this);
			if($this.nextAll("div.prep_phone").html().search(/^\d{10,12}$/)==-1){
				zebra_alert("请输入正确的号码，座机请加区号",function(){
					setTimeout(function(){$this.nextAll("div.prep_edit").click();},300);
				});
				return;
			}else{
				var $lis = $(iwk_call.data4);
				var _arr = [];
				var $this = $(_this);
				for(var i = 0;i < $lis.length;i++){
					var $li = $($lis[i]);
					if($li.attr("data") == $this.parent().attr("data")){
						if($this.find("span:first").is(".checked")){
							$li.find("div.widget_checker>span").removeClass("checked");
							$li.find("div.widget_checker input").prop("checked",false);
						}else{
							$li.find("div.widget_checker>span").addClass("checked");
							$li.find("div.widget_checker input").prop("checked",true);
						}
					}
					_arr.push($li.get(0).outerHTML);
				}
				iwk_call.data4 = _arr.join("");
				iwk_widget.checkbox_click(_this);
			}
		},
		clear_all_data : function(){
			iwk_call.data0 = "";
			iwk_call.data1= "";
			iwk_call.data2 = "";
			iwk_call.data3 = "";
			iwk_call.data4 = "";
			iwk_call._me = "";
			$("#linkid").val("");
		}
};

var iwk_community = {
		data:'',//选人控件得到的总数据
		list_data:'',//当选择了类别时list的总数据
		left_data:'',//过滤后的总数据
		group_data:'',//已发群组数据
		count:20,//选人控件延迟加载时加载数据数量
		pop_users : function(){
			$("div.group_sel").show();
			$.fancybox({
	    		modal: true,
	    		href: "#community_users",
	    		helpers: {overlay: {opacity: 0.2}},
	    		padding:0,
	    		beforeLoad: function(){
	    		}
	    	});
			var _from = "query_customer";
			var sel_vals = $("#range_hid_"+$("#community_type").val()).val();
			if(sel_vals){
				var sel_json = JSON.parse(sel_vals);
				iwk_community.init_sel(sel_json);
			}
			$(".users_left .users_group .group_common:first").click();
		},
		init_sel : function(data){
			var _arr = [];
			for(var i = 0;i < data.length;i++){
				switch(data[i].c_type){
				case 'query_customer':
					_arr.push('<li class="li_customer" customer_type="');
					_arr.push(data[i].customer_type);
					_arr.push('" c_type="');
					_arr.push(data[i].c_type);
					_arr.push('" data="');
					_arr.push(data[i].id);
					_arr.push('">');
					_arr.push('<div class="user_name">');
					_arr.push(data[i].fullname);
					_arr.push('</div><div class="user_company">');
					_arr.push(data[i].company);
					_arr.push('</div>');
					_arr.push('<div class="user_email'+(data[i].email==''?' grey_tab':'')+'" title="');
					_arr.push(data[i].email);
					_arr.push('"></div>');
					_arr.push('<div class="user_phone'+($.trim(data[i].mobile)==''?' grey_tab':'')+'" title="');
					_arr.push(data[i].mobile);
					_arr.push('"></div>');
					_arr.push('</li>');
					break;
				case 'query_workers':
					_arr.push('<li customer_type="');
					_arr.push(data[i].customer_type);
					_arr.push('" c_type="');
					_arr.push(data[i].c_type);
					_arr.push('" data="');
					_arr.push(data[i].id);
					_arr.push('">');
					_arr.push('<div class="user_name">');
					_arr.push(data[i].fullname);
					_arr.push('</div><div class="user_company">');
					_arr.push(data[i].company);
					_arr.push('</div>');
					_arr.push('<div class="user_email'+(data[i].email==''?' grey_tab':'')+'" title="');
					_arr.push(data[i].email);
					_arr.push('"></div>');
					_arr.push('<div class="user_phone'+($.trim(data[i].mobile)==''?' grey_tab':'')+'" title="');
					_arr.push(data[i].mobile);
					_arr.push('"></div>');
					_arr.push('</li>');
					break;
				}
			}
			$("#sel_ul").html(_arr.join(""));
		},
		init_ul_by_data : function(ul_id){
			var _lis = iwk_community.left_data.toLowerCase().match(/<li[a-z0-9_\"\s=]*>.*?<\/li>/g);
			if(!_lis){
				document.getElementById(ul_id).innerHTML = "";
				return;
			}
			var arr_show = [];
			var _len = _lis.length>20?20:_lis.length;
			for(var i = 0;i < _len;i++){
				arr_show.push(_lis[i]);
			}
			if(_lis.length>20){
				iwk_community.count = 20;
				$(".users_left .ul_body").unbind("scroll").bind("scroll",function(){iwk_community.add_ul_by_data(ul_id,_lis)});
			}
			document.getElementById(ul_id).innerHTML = arr_show.join("");
		},
		add_ul_by_data : function(ul_id,_lis){
			var _len = iwk_community.count;
			if(_len == _lis.length){
				return;
			}
			var _count = _len/20;
			if($(".users_left .ul_body").scrollTop() > 640*_count-260){
				var arr_show = [];
				var _len = _lis.length>(20*(_count+1))?20*(_count+1):_lis.length;
				for(var i = 20*_count;i < _len;i++){
					arr_show.push(_lis[i]);
				}
				if(_lis.length>20*(_count)){
					iwk_community.count = 20*(_count+1);
					$(".users_left .ul_body").unbind("scroll").bind("scroll",function(){iwk_community.add_ul_by_data(ul_id,_lis)});
				}
				document.getElementById("unsel_ul").innerHTML = document.getElementById("unsel_ul").innerHTML + arr_show.join("");
			}
		},
		add_ul_by_click : function(ul_id,_lis){
			var _len = iwk_community.count;
			if(_len == _lis.length){
				return;
			}
			var _count = _len/20;
			var arr_show = [];
			var _len = _lis.length>(20*(_count+1))?20*(_count+1):_lis.length;
			for(var i = 20*_count;i < _len;i++){
				arr_show.push(_lis[i]);
			}
			if(_lis.length>20*(_count)){
				iwk_community.count = 20*(_count+1);
				$(".users_left .ul_body").unbind("scroll").bind("scroll",function(){iwk_community.add_ul_by_data(ul_id,_lis)});
			}
			document.getElementById("unsel_ul").innerHTML = document.getElementById("unsel_ul").innerHTML + arr_show.join("");
		},
		search_flag : '',//用来表示pressdown的keyCode
		search_monitor : function(e){
			iwk_community.search_flag = e.keyCode;
		},
		search_users : function(e){
			var search_txt = $.trim($("#users_search").val().toLowerCase());
			//判断是否是中文输入，未输入完毕时不搜索
			if(e.keyCode>64 && e.keyCode <91 && (!iwk_community.search_flag || iwk_community.search_flag == 229)){
				return;
			}
			
			var lis_whole = iwk_community.list_data;
			var right_lis = $("#sel_ul li");
			for(var i = 0,l = right_lis.length;i < l;i++){
				lis_whole = lis_whole.replace(right_lis[i].innerHTML.replace(/\r\n/g,"").toLowerCase(),"");
			}
			if(search_txt == ""){
				iwk_community.left_data = lis_whole;
				iwk_community.init_ul_by_data("unsel_ul");
				return;
			}
			var _result = [];
			var _lis = lis_whole.toLowerCase().match(/<li[a-z0-9_\"\s=]*>.*?<\/li>/g);
			for(var i = 0;i < _lis.length;i++){
				var _li = _lis[i];
				var _res = false;
				var _reg1 = new RegExp('<div[a-z0-9_\\"\\s=]*>'+'[0-9a-zA-Z\u4E00-\u9FFF]*'+search_txt+'[0-9a-zA-Z\u4E00-\u9FFF]*'+'<\/div>');
				if(_reg1.test(_li)){
					_res = true;
				}
				var _reg2 = new RegExp('<div class="user_phone" title="'+'[0-9a-zA-Z\u4E00-\u9FFF]*'+search_txt+'[0-9a-zA-Z\u4E00-\u9FFF]*'+'"></div>');
				if(_reg2.test(_li)){
					_res = true;
				}
				var _reg3 = new RegExp('<div class="user_email" title="'+'[0-9a-zA-Z\u4E00-\u9FFF.@]*'+search_txt+'[0-9a-zA-Z\u4E00-\u9FFF.@]*'+'"></div>');
				if(_reg3.test(_li)){
					_res = true;
				}
				if(_res){
					_result.push(_li);
				}
			}
			iwk_community.left_data = _result.join("");
			iwk_community.init_ul_by_data("unsel_ul");
		},
		switch_user_tab:function(_this){
			$(".users_left .ul_body").removeClass("sendedgroup_ul");
			$("#user_add_all").show();
			$("#unsel_ul").html("");
			iwk_community.data = "";
			iwk_community.list_data = '';
			$(_this).addClass("focus").siblings().removeClass("focus");
			$("#community_sel").show();
			var _from = $(_this).attr("data");
			if(_from == "query_customer"){
				$("div.group_sel").show();
				$("#users_search").show();
			}else if(_from == "query_workers"){
				$("div.group_sel").hide();
				$("#users_search").show();
			}else{
				$(".users_left .ul_body").addClass("sendedgroup_ul");
				$("div.group_sel").hide();
				$("#users_search").hide();
				$("#user_add_all").hide();
			}
			$.post( '' + "inside/community/from:"+_from+"/r:" + Math.round(Math.random() * 1000), function(res) {
				iwk_community.init_unsel(res,_from);
			},'json');
		},
		init_unsel:function(data,from){
			var _arr = [];
			switch(from){
			case 'query_customer':
				for(var i = 0;i < data.length;i++){
					_arr.push('<li class="li_customer" customer_type="');
					_arr.push(data[i].customer_type);
					_arr.push('" c_type="');
					_arr.push(from);
					_arr.push('" data="');
					_arr.push(data[i].id);
					_arr.push('">');
					_arr.push('<div class="user_name">');
					_arr.push(data[i].fullname);
					_arr.push('</div><div class="user_company">');
					_arr.push(data[i].company);
					_arr.push('</div><div class="user_email'+(data[i].email==''?' grey_tab':'')+'" title="');
					_arr.push(data[i].email);
					_arr.push('"></div><div class="user_phone'+($.trim(data[i].mobile)==''?' grey_tab':'')+'" title="');
					_arr.push(data[i].mobile);
					_arr.push('"></div>');
					_arr.push('</li>');
				}
				break;
			case 'query_workers':
				for(var i = 0;i < data.length;i++){
					_arr.push('<li customer_type="');
					_arr.push(data[i].customer_type);
					_arr.push('" c_type="');
					_arr.push(from);
					_arr.push('" data="');
					_arr.push(data[i].id);
					_arr.push('">');
					_arr.push('<div class="user_name">');
					_arr.push(data[i].fullname);
					_arr.push('</div><div class="user_company">');
					_arr.push(data[i].company);
					_arr.push('</div><div class="user_email'+(data[i].email==''?' grey_tab':'')+'" title="');
					_arr.push(data[i].email);
					_arr.push('"></div><div class="user_phone'+($.trim(data[i].mobile)==''?' grey_tab':'')+'" title="');
					_arr.push(data[i].mobile);
					_arr.push('"></div>');
					_arr.push('</li>');
				}
				break;
			case 'query_meeting':
				for(var i = 0;i < data.length;i++){
					_arr.push('<li class="meeting_li" post_id="');
					_arr.push(data[i].post_id);
					_arr.push('">');
					_arr.push(data[i].message);
					_arr.push('</li>');
				}
				break;
			case 'query_sendedgroup':
//				console.log(data);
//				for(var i = 0;i < data.length;i++){
//					if(data[i].num_users > 4){
//						_html = data[i].title+"等"+data[i].num_users+"人";
//					}else{
//						_html = data[i].title;
//					}
//					_arr.push('<li class="group_li" idx="');
//					_arr.push(data[i].id);
//					_arr.push('">');
//					_arr.push(_html);
//					_arr.push('</li>');
//				}
				for(var i = 0;i < data.length;i++){
					var _idx = 0;
					var _persons = [];
					for(var j = 0;j < data[i].accept_users.length;j++){
						if(_idx >= 4){
							break;
						}
						_persons.push(data[i].accept_users[j].fullname);
						_idx ++;
					}
					for(var j = 0;j < data[i].accept_contacts.length;j++){
						if(_idx >= 4){
							break;
						}
						_persons.push(data[i].accept_contacts[j].fullname);
						_idx ++;
					}
					var _len = data[i].accept_users.length + data[i].accept_contacts.length;
					var _html = _persons.join("、");
					if(_len > 4){
						_html += "等"+_len+"人";
					}
					_arr.push('<li class="group_li" idx="');
					_arr.push(i);
					_arr.push('">');
					_arr.push(_html);
					_arr.push('</li>');
				}
				
				iwk_community.group_data = data;
				$("#community_sel").hide();
				$("#unsel_ul").html(_arr.join(""));
			}
			$("#community_sel").hide();
			
			//过滤右边已经存在的
			var right_lis = $("#sel_ul li");
			var res_html = _arr.join("");
			var _id;
			var _reg;
			for(var i = 0;i < right_lis.length;i++){
				_id = right_lis[i].outerHTML.replace(/\r\n/g,"").toLowerCase().match(/data=\"\d+\"/);
				_reg = new RegExp('<li[a-z0-9_\\"\\s=]*'+_id+'[a-z0-9_\\"\\s=]*>.*?<\\/li>');
				res_html = res_html.replace(_reg,"");
			}
			if($("div.group_common.focus").attr("data") != from){
				return;
			}
			iwk_community.left_data = res_html;
			iwk_community.init_ul_by_data("unsel_ul");
			iwk_community.data = res_html;
			iwk_community.list_data = res_html;
		},
		unsel_li_click : function(){
			var $this = $(this);
			if($this.is(".group_li")){
				var _data = iwk_community.group_data[$this.attr('idx')];
				var _arr = [];
				for(var i = 0;i < _data.accept_contacts.length;i++){
					var _contact = _data.accept_contacts[i];
					_arr.push('<li class="li_customer" customer_type="');
					_arr.push(_contact.customer_type);
					_arr.push('" c_type="');
					_arr.push('query_customer');
					_arr.push('" data="');
					_arr.push(_contact.id);
					_arr.push('">');
					_arr.push('<div class="user_name">');
					_arr.push(_contact.fullname);
					_arr.push('</div><div class="user_company">');
					_arr.push(_contact.company);
					_arr.push('</div><div class="user_email'+(_contact.email==''?' grey_tab':'')+'" title="');
					_arr.push(_contact.email);
					_arr.push('"></div><div class="user_phone'+($.trim(_contact.mobile)==''?' grey_tab':'')+'" title="');
					_arr.push(_contact.mobile);
					_arr.push('"></div>');
					_arr.push('</li>');
				}
				for(var i = 0;i < _data.accept_users.length;i++){
					var _contact = _data.accept_users[i];
					_arr.push('<li customer_type=');
					_arr.push('""');
					_arr.push(' c_type="');
					_arr.push('query_workers');
					_arr.push('" data="');
					_arr.push(_contact.id);
					_arr.push('">');
					_arr.push('<div class="user_name">');
					_arr.push(_contact.fullname);
					_arr.push('</div><div class="user_company">');
					_arr.push(_contact.company);
					_arr.push('</div><div class="user_email'+(_contact.email==''?' grey_tab':'')+'" title="');
					_arr.push(_contact.email);
					_arr.push('"></div><div class="user_phone'+(_contact.mobile==''?' grey_tab':'')+'" title="');
					_arr.push(_contact.mobile);
					_arr.push('"></div>');
					_arr.push('</li>');
				}
				var right_lis = $("#sel_ul li");
				var res_html = _arr.join("");
				for(var i = 0;i < right_lis.length;i++){
					res_html = res_html.replace(right_lis[i].outerHTML.replace(/\r\n/g,"").toLowerCase(),"");
				}
				$("#sel_ul").html($("#sel_ul").html()+res_html);
				$this.remove();
				return;
			}
			iwk_community.data = iwk_community.data.replace($(this).get(0).outerHTML,"");
			iwk_community.list_data = iwk_community.list_data.replace($(this).get(0).outerHTML,"");
			iwk_community.left_data = iwk_community.left_data.replace($(this).get(0).outerHTML,"");
			$("#sel_ul").append($(this));
			var _lis = iwk_community.left_data.toLowerCase().match(/<li[a-z0-9_\"\s=]*>.*?<\/li>/g);
			if($("#unsel_ul li").length < 20 && _lis.length > iwk_community.count){
				iwk_community.add_ul_by_click("unsel_ul",_lis);
			}
		},
		sel_li_click : function(){
			var $this = $(this);
			if($("div.group_common.focus").attr("data")!=$this.attr("c_type")){
				$this.remove();
				return;
			}
			iwk_community.data+=$this.get(0).outerHTML;
			iwk_community.list_data+=$this.get(0).outerHTML;
			$("#unsel_ul").append($this);
		},
		confirm_action:function(){
			var _lis = $("#sel_ul li");
			var _res = [];
			var _html_arr = [];
			for(var i = 0,l=_lis.length;i < l;i++){
				var _col = {};
				var $li = $(_lis[i]);
				_col.id = $li.attr("data");
				_col.fullname = $li.find(".user_name").html();
				_col.company = $li.find(".user_company").html();
				_col.mobile = $li.find(".user_phone").attr("title");
				_col.email = $li.find(".user_email").attr("title");
				_col.c_type = $li.attr("c_type");
				_col.customer_type = $li.attr("customer_type");
				_res.push(_col);
				if(i<5){
					_html_arr.push($li.find(".user_name").html());
				}
			}
			if(_lis.length == 0){
				$(".send_range_"+$("#community_type").val()).val("");
				$("#range_hid_"+$("#community_type").val()).val("");
				return;
			}
			if(_lis.length > 5){
				$(".send_range_"+$("#community_type").val()).val(_html_arr.join("、")+"等"+_lis.length+"人");
			}else{
				$(".send_range_"+$("#community_type").val()).val(_html_arr.join("、"));
			}
			$("#range_hid_"+$("#community_type").val()).val(JSON.stringify(_res));
		},
		notice_preview : function(user_photo){
			var _title = $("#notice_title").val();
			if(!editor){
				zebra_alert("请等待页面加载完成或重新刷新页面");
				return;
			}
			var _content = editor.html();
			var send_range = $("#send_range_input").val();
			var _photo = $("#upload_content-button_photo_img").attr("src");
			if(_photo){
				$(".content_cover_wrap").removeClass("exp_img").removeClass("notice_img");
				$("#pop_cover").attr("src",_photo).show();
				$(".content_cover_wrap").show();
			}else{
				$(".content_cover_wrap").addClass("exp_img notice_img");
				$("#pop_cover").hide().attr("src",_photo);
				$(".content_cover_wrap").show();
			}
			$("#community_pop_body .content_user").html($(".left_head>span").html());
			var _date = new Date();
			$("#community_pop_body .post_date").html((_date.getMonth()+1)+"月"+(_date.getDate())+"日 "+_date.getHours()+":"+_date.getMinutes());
			$("#pop_title").html(_title);
			$("#pop_content").html(_content);
			$("#community_pop_body .post_photo").attr("src",user_photo);
			
			$.fancybox({
	    		modal: false,
	    		closebtn:true,
	    		href: "#community_pop_body",
	    		helpers: {overlay: {opacity: 0.2}},
	    		padding:0,
	    		beforeLoad: function(){
	    		},
	    		afterShow:function(){
	    			$(".fancybox-inner").addClass("resizeWidth");
	    		}
	    	});
		},
		abc : Array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
				'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
				'X', 'Y', 'Z'),
		vote_preview : function(_photo){
			var _data = {};
			_data.content = $("#vote_textarea").val();
			_data.vote_type =$("#pf_vote_type").pulldown2("getVal").res;
			_data.vote_end =$("#vote_end").val();
			_data.vote_options = [];
			var _inputs = $(".vote_write_input");
			
			var $vote = $("#community_pop_vote");
			$vote.find(".content_detail").html(_data.content);
			var _html = [];
			for(var i = 0,l = _inputs.length;i < l;i++){
				_html.push('<div class="isvw_option">\
						<div class="widget_radio disabled">\
						<span class="checked"></span>\
					</div>\
					<span class="margin_r">');
				_html.push(iwk_community.abc[i]);
				_html.push('</span>');
				_html.push($(_inputs[i]).val());				
				_html.push('</div>');
			}
			$vote.find(".post_photo").attr("src",_photo);
			$vote.find(".content_title").html("请大家投票");
			$vote.find(".content_text").html(_data.content);
			$vote.find(".content_user").html($(".left_head>span").html());
			
			var $option_lines = $("#community_vote .vote_option_line .vote_write_input");
			var _html = [];
			for(var i = 0;i < $option_lines.length;i++){
				_html.push('<div class="detail_line single">\
							<div class="vote_sel_btn"></div>\
							<div class="detail_cont">'+$($option_lines[i]).val()+'</div>\
							<div class="klearboth"></div>\
						</div>');
			}
			$vote.find(".detail_line").remove();
			$vote.find(".vote_detail").prepend(_html.join(""));
			$vote.find(".exp_end_time").html(_data.vote_end+"到期");
			var _date = new Date();
			$vote.find(".post_date").html((_date.getMonth()+1)+"月"+(_date.getDate())+"日 "+_date.getHours()+":"+_date.getMinutes());
			
			$.fancybox({
	    		modal: false,
	    		closebtn:true,
	    		href: "#community_pop_vote",
	    		helpers: {overlay: {opacity: 0.2}},
	    		padding:0,
	    		beforeLoad: function(){
	    		},
	    		afterShow:function(){
	    			$(".fancybox-inner").addClass("resizeWidth");
	    		}
	    	});
		},
		survey_preview : function(_photo){
			var _data = {};
			_data.questions = [];
			_data.message = $("#survey_textarea").val();
			var $questions = $(".question");
			for(var i = 0,l = $questions.length;i < l;i++){
				var $question = $($questions[i]);
				var _question = {};
				_question.content = $question.find(".survey_write_ques").val();
				_question.options = [];
				var $options = $question.find(".survey_write_input");
				for(var j = 0,jl = $options.length;j<jl;j++){
					_question.options.push($($options[j]).val());
				}
				_data.questions.push(_question);
			}
			
			$survey = $("#community_pop_survey");
			$survey.find(".content_detail").html(_data.message);
			$survey.find(".post_photo").attr("src",_photo);
			$survey.find(".content_title").html("调查问卷");
			$survey.find(".content_text").html(_data.message);
			$survey.find(".content_user").html($(".left_head>span").html());
			
			var _html = [];
			var $questions = $("#community_survey .survey_question_wrap");
			
			for(var i = 0;i < $questions.length;i++){
				var $question = $($questions[i]);
				_html.push('<div class="survey_question_line">');
				_html.push('<div class="survey_question">问题'+(i+1)+'：'+$question.find(".survey_write_ques").val()+'</div>');
				var $options = $question.find(".option_line .survey_write_input");
				var _type = $question.find(".pf_survey_type1").pulldown2("getVal").res;
				if(_type == 2){
					for(var idx in _question.options){
						_id = _question.options[idx].id;
					}
					_html.push('<div class="other_text_wrap" option_id=');
					_html.push(_id);
					_html.push('><div class="widget_ipt_lite_wrap" style="width:300px;margin-left:10px;">\
							<input type="text" class="widget_ipt_lite" style="width:300px;" value=""></div></div>');
				}else{
					for(var j = 0;j < $options.length;j++){
						_html.push('<div class="detail_line single">\
								<div class="vote_sel_btn"></div>\
								<div class="detail_cont">'+$($options[j]).val()+'</div>\
								<div class="klearboth"></div></div>');
					}
				}
				
			}
			
			$survey.find(".survey_question_line").remove();
			$survey.find(".vote_detail").prepend(_html.join(""));
			$survey.find(".exp_end_time").html($("#survey_end").val()+"到期");
			var _date = new Date();
			$survey.find(".post_date").html((_date.getMonth()+1)+"月"+(_date.getDate())+"日 "+_date.getHours()+":"+_date.getMinutes());
			
			$.fancybox({
	    		modal: false,
	    		closebtn:true,
	    		href: "#community_pop_survey",
	    		helpers: {overlay: {opacity: 0.2}},
	    		padding:0,
	    		beforeLoad: function(){
	    		},
	    		afterShow:function(){
	    			$(".fancybox-inner").addClass("resizeWidth");
	    		}
	    	});
		},
		toggle_detail : function(){
			var _time = 800;
			var $this = $(this);
			var _this = $(this).closest("li");
			var content_wrap = _this.find(".show_content_wrap");
			var _content = _this.find(".show_content");
			var _img = _this.find(".show_cover");
			var show_cover_wrap = _this.find(".show_cover_wrap");
			if(_content.is(".content_height")){
					_content.removeClass("content_height");
					content_wrap.slideDown(_time);
					$this.find("div.cont").html("收起").next().removeClass().addClass("up_arrow");
					$("html,body").animate({scrollTop:_this.position().top+50},800);
					_this.find(".show_content img").show();
			}else{
					_content.addClass("content_height");
					$this.find("div.cont").html("展开").next().removeClass().addClass("down_arrow");
					$("html,body").animate({scrollTop:_this.position().top+50},800);
					_this.find(".show_content img").hide();
			}
		},
		save_post : function(_status,_content){
			var _data = {};
			if($("#meeting_val").val()){
				_data.meeting_id = $("#meeting_val").val();
			}
			if(!$.trim($("#notice_title").val())){
				zebra_alert("请输入标题");
				return;
			}
			if(!$("#range_hid_notice").val() && !_data.meeting_id){
				zebra_alert("请选择发送范围");
				return;
			}
			if(!$.trim(_content.replace(/&nbsp;/g,""))){
				zebra_alert("请输入正文内容");
				return;
			}
			fancylay.block();
			_data.title = $("#notice_title").val();
			_data.post_temp_id =  iwk_cfg_postform.temp_id;
			_data.status = _status;
			_data.content = _content;
			
			_data.is_sms = $("#is_sms_post").prop("checked")?1:0;
			if($("#upload_content-button_photo_img").length != 0){
				_data.cover = $("#upload_content-button_photo_img").attr("data");
			}
			var resend_len = 0;
			if($("#save_type").val()){//如果是编辑时保存
				if($("#notice_attachs").length != 0){
					var attach_ids = [];
					var remove_ids = [];
					var $attachs = $("#notice_attachs ");
					var _images = $attachs.find(".attach_images>a");
					for(var i = 0;i < _images.length;i++){
						var $img = $(_images[i]);
						if($img.is(".selected")){
							attach_ids.push($(_images[i]).attr("attach_id"));
						}else{
							remove_ids.push($(_images[i]).attr("attach_id"));
						}
					}
					var $files = $attachs.find(".attach_file");
					for(var i = 0;i < $files.length;i++){
						if($($files[i]).is(".selected")){
							attach_ids.push($($files[i]).attr("attach_id"));
						}else{
							remove_ids.push($($files[i]).attr("attach_id"));
						}
					}
					_data.attach_ids = attach_ids.join(",");
					_data.remove_ids = remove_ids.join(",");
					resend_len = attach_ids.length;
				}
			}else{
				if($("#notice_attachs").length != 0){
					var attach_ids = [];
					var $attachs = $("#notice_attachs ");
					var _images = $attachs.find(".attach_images>a");
					for(var i = 0;i < _images.length;i++){
						attach_ids.push($(_images[i]).attr("attach_id"));
					}
					var $files = $attachs.find(".attach_file");
					for(var i = 0;i < $files.length;i++){
						attach_ids.push($($files[i]).attr("attach_id"));
					}
					_data.attach_ids = attach_ids.join(",");
					resend_len = attach_ids.length;
				}
			}
			_data.send_customer = [];
			_data.send_workers = [];
			var vote_range = $("#range_hid_notice").val();
			if(vote_range){
				var vote_range_json = JSON.parse(vote_range);
				for(var i = 0;i < vote_range_json.length;i++){
					switch(vote_range_json[i].c_type){
					case 'query_customer':
						_data.send_customer.push(vote_range_json[i].id);
						break;
					case 'query_workers':
						_data.send_workers.push(vote_range_json[i].id);
						break;
					}
				}
			}
			var _len = $("#postform_attach_queue>.uploadify-queue-item").length;
			if(_len+resend_len >10){
				zebra_alert("上传附件超过了10个，请删除超出附件");
				fancylay.unblock();
				return;
			}
			if($("#save_type").val()){
				_data.save_type = $("#save_type").val();
			}
			$.post( '' + "inside/community/from:save_post/r:" + Math.round(Math.random() * 1000),_data, function(res) {
				if(res.status == "ok"){
					window.location.reload();
	//				iwk_community.init_post_list([1,res.result],res.result[0].status,'save');
				}else{
					if(res.status == "sms_not"){
						zebra_confirm("当前短信不足，无法发送短信，是否继续？",function(){
							$("#is_sms_post").prop("checked",false);
							iwk_community.save_post(1,editor.html());
						});
					}else{
						zebra_alert(res.msg);
					}
					fancylay.unblock();
				}
			},'json');
			$("#save_type").val("");
		},
		save_meeting : function(_status,_content){
			var _address = $.trim($("#meeting_address").val());
			var _lng = $.trim($("#meeting_lng").val());
			var _lat = $.trim($("#meeting_lat").val());
			
			if(!$.trim($("#meeting_title").val())){
				zebra_alert("请输入标题");
				return;
			}
			if(!$("#range_hid_meeting").val()){
				zebra_alert("请选择发送范围");
				return;
			}
			if(_address == ''){
				zebra_alert("请输入地址");
				return;
			}
			if(!$.trim(_content.replace(/&nbsp;/g,""))){
				zebra_alert("请输入正文内容");
				return;
			}
			fancylay.block();
			var _data = {};
			_data.title = $("#meeting_title").val();
			_data.status = _status;
			_data.content = _content;
			_data.address = _address;
			_data.lng = _lng;
			_data.lat = _lat;
			_data.is_sms = $("#is_sms_meeting").prop("checked")?1:0;
			_data.start_time = iwk_date.formatStr($("#meeting_begin").val()).getTime()/1000;
			_data.end_time = iwk_date.formatStr($("#meeting_end").val()).getTime()/1000;
			if($("#upload_meeting-button_photo_img").length != 0){
				_data.cover = $("#upload_meeting-button_photo_img").attr("data");
			}
			
			_data.send_customer = [];
			_data.send_workers = [];
			var vote_range = $("#range_hid_meeting").val();
			if(vote_range){
				var vote_range_json = JSON.parse(vote_range);
				for(var i = 0;i < vote_range_json.length;i++){
					switch(vote_range_json[i].c_type){
					case 'query_customer':
						_data.send_customer.push(vote_range_json[i].id);
						break;
					case 'query_workers':
						_data.send_workers.push(vote_range_json[i].id);
						break;
					}
				}
			}else{
				fancylay.unblock();
				zebra_alert("请选择发送范围");
				return;
			}
			$.post( '' + "inside/community/from:save_meeting/r:" + Math.round(Math.random() * 1000),_data, function(res) {
				if(res.status == "ok"){
					window.location.reload();
				}else{
					if(res.status == "sms_not"){
						zebra_confirm("当前短信不足，无法发送短信，是否继续？",function(){
							$("#is_sms_meeting").prop("checked",false);
							iwk_community.save_meeting(1,editor_meeting.html());
						});
					}else{
						zebra_alert(res.msg);
					}
					fancylay.unblock();
				}
			},'json');
		},
		save_vote : function(){
			if(!$.trim($("#vote_textarea").val().replace(/&nbsp;/g,""))){
				zebra_alert("请输入正文内容");
				return;
			}
			fancylay.block();
			var _data = {};
			_data.content = $("#vote_textarea").val();
			_data.vote_type =$("#pf_vote_type").pulldown2("getVal").res;
			_data.vote_end =$("#vote_end").val();
			_data.vote_options = [];
			var _inputs = $(".vote_write_input");
			for(var i = 0;i < _inputs.length;i++){
				_data.vote_options.push($(_inputs[i]).val());
			}
			var resend_len = 0;
			if($("#vote_attachs").length != 0){
				var attach_ids = [];
				var $attachs = $("#vote_attachs ");
				var _images = $attachs.find(".attach_images>a");
				for(var i = 0;i < _images.length;i++){
					attach_ids.push($(_images[i]).attr("attach_id"));
				}
				var $files = $attachs.find(".attach_file");
				for(var i = 0;i < $files.length;i++){
					attach_ids.push($($files[i]).attr("attach_id"));
				}
				_data.attach_ids = attach_ids.join(",");
				resend_len = attach_ids.length;
			}
			_data.post_temp_id =  iwk_cfg_postform.temp_id;
			_data.status = 1;
			_data.send_customer = [];
			_data.send_workers = [];
			var vote_range = $("#range_hid_vote").val();
			if(vote_range){
				var vote_range_json = JSON.parse(vote_range);
				for(var i = 0;i < vote_range_json.length;i++){
					switch(vote_range_json[i].c_type){
					case 'query_customer':
						_data.send_customer.push(vote_range_json[i].id);
						break;
					case 'query_workers':
						_data.send_workers.push(vote_range_json[i].id);
						break;
					}
				}
			}else{
				zebra_alert("请选择发送范围");
				fancylay.unblock();
				return;
			}
			var _len = $("#postform_attach_queue>.uploadify-queue-item").length;
			if(_len+resend_len >10){
				zebra_alert("上传附件超过了10个，请删除超出附件");
				fancylay.unblock();
				return;
			}
			$.post( '' + "inside/community/from:save_vote/r:" + Math.round(Math.random() * 1000),_data, function(res) {
				if(res.status == "ok"){
					window.location.reload();
				}else{
					zebra_alert(res.msg);
					fancylay.unblock();
				}
			},'json');
		},
		save_survey : function(){
			if(!$.trim($("#survey_textarea").val().replace(/&nbsp;/g,""))){
				zebra_alert("请输入正文内容");
				return;
			}
			fancylay.block();
			var _data = {};
			_data.questions = [];
			_data.post_temp_id =  iwk_cfg_postform.temp_id;
			_data.send_customer = [];
			_data.send_workers = [];
			var resend_len = 0;
			if($("#survey_attachs").length != 0){
				var attach_ids = [];
				var $attachs = $("#survey_attachs");
				var _images = $attachs.find(".attach_images>a");
				for(var i = 0;i < _images.length;i++){
					attach_ids.push($(_images[i]).attr("attach_id"));
				}
				var $files = $attachs.find(".attach_file");
				for(var i = 0;i < $files.length;i++){
					attach_ids.push($($files[i]).attr("attach_id"));
				}
				_data.attach_ids = attach_ids.join(",");
				resend_len = attach_ids.length;
			}
			_data.end_time = iwk_date.formatFullTime($("#survey_end").val()).getTime()/1000;
			_data.message = $("#survey_textarea").val();
			var $questions = $(".question");
			for(var i = 0,l = $questions.length;i < l;i++){
				var $question = $($questions[i]);
				var _question = {};
				_question.content = $question.find(".survey_write_ques").val();
				_question.type = $question.find(".pf_survey_type1").pulldown2("getVal").res;
				_question.option_type =  $question.find(".pf_survey_type2").pulldown2("getVal").res;
				_question.is_subjective =  $question.find(".isSendSms").val();
				_question.options = [];
				var $options = $question.find(".survey_write_input");
				for(var j = 0,jl = $options.length;j<jl;j++){
					_question.options.push($($options[j]).val());
				}
				_data.questions.push(_question);
			}
			var vote_range = $("#range_hid_survey").val();
			if(vote_range){
				var vote_range_json = JSON.parse(vote_range);
				for(var i = 0;i < vote_range_json.length;i++){
					switch(vote_range_json[i].c_type){
					case 'query_customer':
						_data.send_customer.push(vote_range_json[i].id);
						break;
					case 'query_workers':
						_data.send_workers.push(vote_range_json[i].id);
						break;
					}
				}
			}else{
				zebra_alert("请选择发送范围");
				fancylay.unblock();
				return;
			}
			var _len = $("#postform_attach_queue>.uploadify-queue-item").length;
			if(_len+resend_len >10){
				zebra_alert("上传附件超过了10个，请删除超出附件");
				fancylay.unblock();
				return;
			}
			$.post( '' + "inside/community/from:save_survey/r:" + Math.round(Math.random() * 1000),_data, function(res) {
				if(res.status == "ok"){
					window.location.reload();
				}else{
					zebra_alert(res.msg);
					fancylay.unblock();
				}
			},'json');
		},
		search_customer_by_type : function(){	
			var _type = $(this).attr("data");
			var lis_whole = iwk_community.data;
			var right_lis = $("#sel_ul li");
			for(var i = 0,l =  right_lis.length;i <l;i++){
				_id = right_lis[i].outerHTML.replace(/\r\n/g,"").toLowerCase().match(/data=\"\d+\"/);
				_reg = new RegExp('<li[a-z0-9_\\"\\s=]*'+_id+'[a-z0-9_\\"\\s=]*>.*?<\\/li>');
				lis_whole = lis_whole.replace(_reg,"");
			}
	//		var $lis = $(lis_whole);
			if(!_type){
				iwk_community.list_data = lis_whole;
				iwk_community.left_data = lis_whole;
				iwk_community.init_ul_by_data("unsel_ul");
				return;
			}
			var _result = [];
			
			var _reg = new RegExp('<li[a-z0-9_\\"\\s=]*'+'customer_type="'+_type+'"'+'[a-z0-9_\\"\\s=]*>.*?<\\/li>','g');
			_result = lis_whole.match(_reg);
			
			if(_result && _result.length > 0){
				iwk_community.list_data = _result.join("");
				iwk_community.left_data = _result.join("").replace(/\r\n/g,"");
			}else{
				iwk_community.list_data = '';
				iwk_community.left_data = '';
			}
			iwk_community.init_ul_by_data("unsel_ul");
		},
		add_all : function(){
			var from = $(".users_group .group_common.focus").attr("data");
			$("#unsel_ul").empty();
			document.getElementById("sel_ul").innerHTML = document.getElementById("sel_ul").innerHTML + iwk_community.left_data;
			iwk_community.left_data = "";
		},
		reselect : function(){
			$("#sel_ul").empty();
			$(".group_common.focus").click();
			$("#range_hid_"+$("#community_type").val()).val("");
			$(".send_range_"+$("#community_type").val()).val("");
		},
		init_comment_html : function(_comments){
			if(!_comments){
				return;
			}
			var _html = [];
			for(var n = 0;n < _comments.length;n++){
				var _comment = _comments[n];
				_html.push('<li comment_id="');
				_html.push(_comment.comment_id);
				_html.push('">\
						<img class="reply_photo" alt="" src="');
				_html.push(_comment.user_photo);
				_html.push('">');
				_html.push('<div class="reply_content">');
				_html.push('<div class="reply_user">');
				_html.push(_comment.name);
				_html.push('</div>');
				_html.push(_comment.comment_message);
				_html.push('<div class="reply_time">');
				_html.push(iwk_date.formatFullDate(new Date(Number(_comment.date)*1000)));
				_html.push('</div>');
				_html.push('</div>');
				_html.push('<div class="reply" c_name="');
				_html.push(_comment.name);
				_html.push('" parent="');
				_html.push(_comment.comment_id);
				_html.push('">回复</div>\
						<div class="klearboth"></div>');
				if(_comment.attachment){
					_html.push('<div class="attachs"><div class="attach_images klear" style="width:100%;">');
					for(var j = 0;j< _comment.attachment['image'].length;j++){
						_image =  _comment.attachment['image'][j];
						_pre = 0;
						_next = 0;
						if(j>0){
							_pre = 1;
						}
						if(j+1<_comment.attachment['image'].length){
							_next = 1;
						}
						_html.push('<a href="javascript:;" data="'+''+'inside/getattachment/id:'+_image.attachment_id+'" class="attach_image first" onclick="iwk_post.view_img_attach(this,'+_pre+','+_next+');">\
								<img src="'+''+'inside/get_file/id:'+_image.attachment_id+'">\
								</a>');
					}
					_html.push('</div>');
					
					for(var j = 0;j < _comment.attachment['file'].length;j++){
						_file =  _comment.attachment['file'][j];
						_html.push('<div class="attach_file '+_file.file_type+'" onclick="iwk_post.view_file_attach(this);" data="'+''+'inside/getattachment/id:'+_file.attachment_id+'">');
						_html.push('<a href="javascript:;" title="'+_file.title+'" >'+_file.title+'</a>');
						_html.push('</div>');
					}
					_html.push('</div>');
				}
				if(_comment.recomments){
					for(var i = 0;i < _comment.recomments.length;i++){
						var _recomment = _comment.recomments[i];
						_html.push('<div class="recomment">');
						_html.push('<img class="reply_photo" src="');
						_html.push(_recomment.user_photo);
						_html.push('">');
						_html.push('<div class="reply_content">');
						_html.push('<div class="reply_user">');
						_html.push(_recomment.name);
						_html.push('</div>');
						_html.push(_recomment.comment_message);
						_html.push('<div class="reply_time">');
						_html.push(iwk_date.formatFullDate(new Date(Number(_recomment.date)*1000)));
						_html.push('</div>');
						_html.push('</div>');
						_html.push('<div class="klearboth"></div>');
						
						if(_recomment.attachment){
							_html.push('<div class="attachs"><div class="attach_images klear" style="width:100%;">');
							for(var j = 0;j< _recomment.attachment['image'].length;j++){
								_image =  _recomment.attachment['image'][j];
								_pre = 0;
								_next = 0;
								if(j>0){
									_pre = 1;
								}
								if(j+1<_recomment.attachment['image'].length){
									_next = 1;
								}
								_html.push('<a href="javascript:;" data="'+''+'inside/getattachment/id:'+_image.attachment_id+'" class="attach_image first" onclick="iwk_post.view_img_attach(this,'+_pre+','+_next+');">\
										<img src="'+''+'inside/get_file/id:'+_image.attachment_id+'">\
										</a>');
							}
							_html.push('</div>');
							
							for(var j = 0;j < _recomment.attachment['file'].length;j++){
								_file =  _recomment.attachment['file'][j];
								_html.push('<div class="attach_file '+_file.file_type+'" onclick="iwk_post.view_file_attach(this);" data="'+''+'inside/getattachment/id:'+_file.attachment_id+'">');
								_html.push('<a href="javascript:;" title="'+_file.title+'" >'+_file.title+'</a>');
								_html.push('</div>');
							}
							_html.push('</div>');
						}
						
						_html.push('</div>');
					}
					_html.push('<div class="klearboth"></div>');
				}
				
				_html.push('</li>');
			}
			return _html.join("");
		},
		init_send_range:function(post){
			var _res = [];
			
			for(var m in post.send_workers){
				var _worker = post.send_workers[m];
				var _col = {};
				_col.id = _worker.id;
				_col.fullname = _worker.fullname;
				_col.mobile = _worker.mobile;
				_col.email = _worker.work_email;
				_col.c_type = 'query_workers';
				_col.customer_type = '';
				_res.push(_col);
			}
			
			for(var m in post.send_customer){
				var _worker = post.send_customer[m];
				var _col = {};
				_col.id = _worker.id;
				_col.fullname = _worker.fullname;
				_col.mobile = _worker.mobile;
				_col.email = _worker.email;
				_col.c_type = 'query_customer';
				_col.customer_type = '';
				_res.push(_col);
			}
			
			return '<input type="hidden" class="post_send_range" value=\''+JSON.stringify(_res)+'\'>';
		},
		/**
		 * _list:post的list内容
		 * _status:0表示草稿箱，1表示已发送
		 * _from:用来区分从哪里调用该方法
		 */
		init_post_list : function(_list,_status,_from){
			var list_count = _list[0];
			_list = _list[1];
			var _html = [];
			for(var i = 0,l = _list.length;i < l;i++){
				var post = _list[i];
				switch(post.type){
				case 'EXP_NOTICE':
					_html.push('<li data="');
					_html.push(post.id);
					_html.push('" id="');
					_html.push('public_'+post.id);
					_html.push('" class="li_notice">');
					_html.push(iwk_community.init_send_range(post));
					
					if(post.photo == ""){
						_html.push('<div class="show_cover_wrap exp_img notice_img">\
									<img class="show_cover hide" src="');
						_html.push(post.photo);
						_html.push('">\
								</div>');
					}else{
						_html.push('<div class="show_cover_wrap">\
									<img class="show_cover" src="');
						_html.push(post.photo);
						_html.push('">\
								</div>');
					}
					_html.push('<div class="show_content_wrap">');
					_html.push('<div class="show_content_title">');
					_html.push(post.title);
					_html.push('</div>\
							<div class="show_content content_height">');
					_html.push(post.content);
					_html.push('</div>');
					_html.push('<div class="klearboth"></div>');
					if(post.has_attachment){
						_html.push('<div class="attachs"><div class="attach_images klear" style="width:100%;">');
						for(var j = 0;j< post.attachment['image'].length;j++){
							_image =  post.attachment['image'][j];
							_pre = 0;
							_next = 0;
							if(j>0){
								_pre = 1;
							}
							if(j+1<post.attachment['image'].length){
								_next = 1;
							}
							_html.push('<a href="javascript:;" attach_id="'+_image.attachment_id+'" data="'+''+'inside/getattachment/id:'+_image.attachment_id+'" class="attach_image first" onclick="iwk_post.view_img_attach(this,'+_pre+','+_next+');">\
									<img src="'+''+'inside/get_file/id:'+_image.attachment_id+'">\
									</a>');
						}
						_html.push('</div>');
						
						for(var j = 0;j < post.attachment['file'].length;j++){
							_file =  post.attachment['file'][j];
							_html.push('<div class="attach_file '+_file.file_type+'" attach_id="'+_file.attachment_id+'" onclick="iwk_post.view_file_attach(this);" data="'+''+'inside/getattachment/id:'+_file.attachment_id+'">');
							_html.push('<a href="javascript:;" title="'+_file.title+'" >'+_file.title+'</a>');
							_html.push('</div>');
						}
						
						for(var j = 0;j < post.attachment['sound'].length;j++){
							_sound =  post.attachment['sound'][j];
							_html.push('<a href="javascript:;" onclick="iwk_priv.play_audio('+''+'inside/getfile/aid:'+_sound.attachment_id+', this, event)" class="attach_sound_play"></a>');
						}
						_html.push('</div>');
					}
					_html.push('<div class="klearboth"></div>\
						</div><div class="klearboth"></div>');
					_html.push('<div class="show_notice_detail">	<div class="cont">展开</div><div class="down_arrow"></div></div>');
					_html.push('<div class="show_content_footer">\
							<div class="show_footer1">');
					post.post_date = new Date(Number(post.post_date)*1000);
					_html.push(post.post_date.getFullYear()+"年"+(post.post_date.getMonth()+1)+"月"+post.post_date.getDate()+"日 "+(post.post_date.getHours())+":"+(post.post_date.getMinutes()<10?"0"+post.post_date.getMinutes():post.post_date.getMinutes()));
					var _users = [];
					var _display_users = [];
					var index = 0;
					for(var j in post.send_customer){
						index++;
						_users.push(post.send_customer[j].fullname);
						if(index <=5){
							_display_users.push(post.send_customer[j].fullname);
						}
					}
					for(var j in post.send_workers){
						index++;
						_users.push(post.send_workers[j].fullname);
						if(index <=5){
							_display_users.push(post.send_workers[j].fullname);
						}
					}
					_html.push('</div>\
							<div class="show_footer2" title ='+_users.join("、")+'>');
					if(_users.length > 5){
						_html.push("发送至："+_display_users.join("、")+"等"+index+"人");
					}else{
						_html.push("发送至："+_display_users.join("、"));
					}
					_html.push('</div>');
					
					if(post.can_edit){
						_html.push('<div class="show_btns edit_wrap"><div class="edit"></div><div class="fl">编辑</div></div>');
					}
					if(post.can_del){
						_html.push('<div class="show_btns del_wrap"><div class="del"></div><div class="fl">删除</div></div>');
					}
					if(_status != 0){
						_html.push('<div class="btns_wrap reply_btns_wrap">\
									<div class="reply_img"></div>\
									<div class="fl">');
						_html.push(post.comments_num);
						_html.push('条回复</div>\
									<div class="klearboth"></div>\
								</div>');
						_html.push('<div class="show_btns statistic_wrap" is_sms='+post.is_sms+'><div class="statistic"></div><div class="fl">统计</div></div>');	
//						_html.push('<div class="show_btns resend_wrap"><div class="resend"></div><div class="fl">重发</div></div>');
					}
					
					_html.push('</div>\
							<div class="klearboth"></div>');
					_html.push('<div class="post_footer hide">\
							<div class="footer_arrow"></div>\
							<input type="text" class="footer_input">\
							<div class="footer_send_btn" parent="0" data="public_');
					_html.push(post.id);
					_html.push('" onclick="iwk_community.comment_send(this);">发&nbsp;送</div>');
					_html.push('<div class="klearboth"></div>');
					_html.push('<a class="comment_attach" id="comment_attach_');
					_html.push(post.id);
					_html.push('"></a>');
					_html.push('<div class="community_comment_attach_queue" id="comment_attach_queue_'+post.id+'"></div>');
					_html.push('<div class="klearboth"></div>');
					_html.push('<ul class="reply_list">');
					_html.push(iwk_community.init_comment_html(post.comments));
					_html.push('</ul>\
							<div class="toggle_replay_wrap">\
								<div class="toggle_detail">收起</div>\
								<div class="up_arrow"></div>\
								<div class="klearboth"></div>\
							</div>\
						</div>\
					</div>');
					_html.push('</li>');
					break;
					
				case 'EXP_MEETING':
					_html.push('<li data="');
					_html.push(post.id);
					_html.push('" id="');
					_html.push('public_'+post.id);
					_html.push('" class="li_meeting">');
					_html.push(iwk_community.init_send_range(post));
					
					if(post.photo == ""){
						_html.push('<div class="show_cover_wrap exp_img meeting_img">\
									<img class="show_cover hide" src="');
						_html.push(post.photo);
						_html.push('">\
								</div>');
					}else{
						_html.push('<div class="show_cover_wrap">\
									<img class="show_cover" src="');
						_html.push(post.photo);
						_html.push('">\
								</div>');
					}
					_html.push('<div class="show_content_wrap">');
					_html.push('<div class="show_content_title">');
					_html.push(post.title);
					_html.push('</div>\
							<div class="show_content content_height">');
					_html.push(post.content);
					_html.push('</div>');
					_html.push('<div class="klearboth"></div>');
					_html.push('\
						</div><div class="klearboth"></div>');
					_html.push('<div class="meeting_time">');
					_html.push('<div class="line"><div class="line_label">会议地点</div><div class="line_cont" title='+post.address+'>'+post.address+'</div><div class="klearboth"></div></div>');
					_html.push('<div class="line"><div class="line_label">会议时间</div><div class="line_cont">'+post.start_time+" ---- "+post.end_time+'</div><div class="klearboth"></div></div>');
					_html.push('</div><div class="klearboth"></div>');
					_html.push('<div class="show_notice_detail">	<div class="cont">展开</div><div class="down_arrow"></div></div>');
					_html.push('<div class="show_content_footer">\
							<div class="show_footer1">');
					post.post_date = new Date(Number(post.post_date)*1000);
					_html.push(post.post_date.getFullYear()+"年"+(post.post_date.getMonth()+1)+"月"+post.post_date.getDate()+"日 "+(post.post_date.getHours())+":"+(post.post_date.getMinutes()<10?"0"+post.post_date.getMinutes():post.post_date.getMinutes()));
					var _users = [];
					var _display_users = [];
					var index = 0;
					for(var j in post.send_customer){
						index++;
						_users.push(post.send_customer[j].fullname);
						if(index <=5){
							_display_users.push(post.send_customer[j].fullname);
						}
					}
					for(var j in post.send_workers){
						index++;
						_users.push(post.send_workers[j].fullname);
						if(index <=5){
							_display_users.push(post.send_workers[j].fullname);
						}
					}
					_html.push('</div>\
							<div class="show_footer2" title ='+_users.join("、")+'>');
					if(_users.length > 5){
						_html.push("发送至："+_display_users.join("、")+"等"+index+"人");
					}else{
						_html.push("发送至："+_display_users.join("、"));
					}
					_html.push('</div>');
					
					if(post.can_edit){
						_html.push('<div class="show_btns edit_wrap"><div class="edit"></div><div class="fl">编辑</div></div>');
					}
					if(post.can_del){
						_html.push('<div class="show_btns del_wrap"><div class="del"></div><div class="fl">删除</div></div>');
					}
					if(_status != 0){
						if(post.can_close){
							_html.push('<div class="show_btns end_meeting_wrap"><div class="end_meeting"></div><div class="fl">关闭会议</div></div>');	
						}
						_html.push('<div class="show_btns statistic_wrap" is_sms='+post.is_sms+'><div class="statistic"></div><div class="fl">统计</div></div>');	
						_html.push('<div class="show_btns registration_wrap"><div class="registration"></div><div class="fl">签到报表</div></div>');	
//						_html.push('<div class="show_btns resend_wrap"><div class="resend"></div><div class="fl">重发</div></div>');
					}
					
					_html.push('</div>\
							<div class="klearboth"></div>');
					_html.push('<div class="post_footer hide">\
							<div class="footer_arrow"></div>\
							<input type="text" class="footer_input">\
							<div class="footer_send_btn" parent="0" data="public_');
					_html.push(post.id);
					_html.push('" onclick="iwk_community.comment_send(this);">发&nbsp;送</div>');
					_html.push('<div class="klearboth"></div>');
					_html.push('<a class="comment_attach" id="comment_attach_');
					_html.push(post.id);
					_html.push('"></a>');
					_html.push('<div class="community_comment_attach_queue" id="comment_attach_queue_'+post.id+'"></div>');
					_html.push('<div class="klearboth"></div>');
					_html.push('<ul class="reply_list">');
					_html.push(iwk_community.init_comment_html(post.comments));
					_html.push('</ul>\
							<div class="toggle_replay_wrap">\
								<div class="toggle_detail">收起</div>\
								<div class="up_arrow"></div>\
								<div class="klearboth"></div>\
							</div>\
						</div>\
					</div>');
					_html.push('</li>');
					break;
						
				case 'EXP_VOTE':
					_html.push('<li data="');
					_html.push(post.id);
					_html.push('" class="li_vote">');
					_html.push(iwk_community.init_send_range(post));
					_html.push('<div class="show_cover_wrap exp_img vote_img">\
							</div>');
					_html.push('<div class="show_content_wrap">\
							<div class="show_content_title">请大家投票</div>\
							<div class="show_content">');
					_html.push(post.content);
					_html.push('</div>');
					_html.push('<div class="klearboth"></div>');
					if(post.has_attachment){
						_html.push('<div class="attachs"><div class="attach_images klear" style="width:100%;">');
						for(var j = 0;j< post.attachment['image'].length;j++){
							_image =  post.attachment['image'][j];
							_pre = 0;
							_next = 0;
							if(j>0){
								_pre = 1;
							}
							if(j+1<post.attachment['image'].length){
								_next = 1;
							}
							_html.push('<a href="javascript:;" attach_id="'+_image.attachment_id+'" data="'+''+'inside/getattachment/id:'+_image.attachment_id+'" class="attach_image first" onclick="iwk_post.view_img_attach(this,'+_pre+','+_next+');">\
									<img src="'+''+'inside/get_file/id:'+_image.attachment_id+'">\
									</a>');
						}
						_html.push('</div>');
						
						for(var j = 0;j < post.attachment['file'].length;j++){
							_file =  post.attachment['file'][j];
							_html.push('<div class="attach_file '+_file.file_type+'" attach_id="'+_file.attachment_id+'" onclick="iwk_post.view_file_attach(this);" data="'+''+'inside/getattachment/id:'+_file.attachment_id+'">');
							_html.push('<a href="javascript:;" title="'+_file.title+'" >'+_file.title+'</a>');
							_html.push('</div>');
						}
						
						for(var j = 0;j < post.attachment['sound'].length;j++){
							_sound =  post.attachment['sound'][j];
							_html.push('<a href="javascript:;" onclick="iwk_priv.play_audio('+''+'inside/getfile/aid:'+_sound.attachment_id+', this, event)" class="attach_sound_play"></a>');
						}
						_html.push('</div>');
					}
					_html.push('<div class="klearboth"></div>\
						</div><div class="klearboth"></div>');
					_html.push('<div class="show_vote_detail">\
							<div class="cont">展开</div>\
							<div class="down_arrow"></div>\
						</div>');
					_html.push('<div class="vote_detail hide">');
					
					_html.push('<div class="isvw_wrap">\
						<div class="isvw_ttl">');
					_html.push(post.content);
					_html.push('</div>\
						<div class="isvw_options">');
				
					if(post.vote_result.length != 0){
						var _sum = 0;
						var options_counts = {};
						for(var m = 0;m < post.option_ids.length;m++){
							var _option = post.vote_result[post.option_ids[m]];
							var option_count = 0;
							for(var j in _option){
								option_count++;
							}
							options_counts[post.option_ids[m]] = option_count;
							_sum += option_count;
						}
						for(var m = 0;m < post.options.length;m++){
							var _count = options_counts[post.options[m].id];
							_html.push('<div class="isvw_option">\
								<div class="widget_radio disabled">\
									<span class="checked"></span>\
								</div><span class="margin_r">'+iwk_community.abc[m]+'</span>');
							_html.push( '<span class="option_content">'+post.options[m].content+'</span>');
							_html.push('</div>');
							_html.push('<div class="isvw_rate_block">\
								<div class="isvw_rate_wrap">\
									<div class="isvw_rate" style="width:');
							_html.push(parseInt(_count/_sum*100));
							_html.push('%;"></div>\
								</div>\
								<span class="isvw_rate_val">');
							_html.push(_count+" ("+parseInt(_count/_sum*100)+"%)");
							_html.push('</span>\
								<div class="klear"></div>\
							</div>');
						}
						_html.push("</div></div>");
						
					}else{
						var _sum = 0;
						var options_counts = {};
						for(var m = 0;m < post.options.length;m++){
							_html.push('<div class="isvw_option">\
								<div class="widget_radio disabled">\
									<span class="checked"></span>\
								</div><span class="margin_r">'+iwk_community.abc[m]+'</span>');
							_html.push('<span class="option_content">'+ post.options[m].content+'</span>');
							_html.push('</div>');
							_html.push('<div class="isvw_rate_block">\
								<div class="isvw_rate_wrap">\
									<div class="isvw_rate" style="width:');
							_html.push(0);
							_html.push('%;"></div>\
								</div>\
								<span class="isvw_rate_val">');
							_html.push(0+" ("+0+"%)");
							_html.push('</span>\
								<div class="klear"></div>\
							</div>');
						}
						_html.push("</div></div>");
					}
					_html.push('</div>');
					_html.push('<div class="show_content_footer">\
					<div class="show_footer1">');
					post.post_date = new Date(Number(post.post_date)*1000);
					_html.push(post.post_date.getFullYear()+"年"+(post.post_date.getMonth()+1)+"月"+post.post_date.getDate()+"日 "+(post.post_date.getHours())+":"+(post.post_date.getMinutes()<10?'0'+post.post_date.getMinutes():post.post_date.getMinutes()));
					var _users = [];
					var _display_users = [];
					var index = 0;
					for(var j in post.send_customer){
						index++;
						_users.push(post.send_customer[j].fullname);
						if(index <=5){
							_display_users.push(post.send_customer[j].fullname);
						}
					}
					for(var j in post.send_workers){
						index++;
						_users.push(post.send_workers[j].fullname);
						if(index <=5){
							_display_users.push(post.send_workers[j].fullname);
						}
					}
					_html.push('</div>\
							<div class="show_footer2" title ='+_users.join("、")+'>');
					if(_users.length > 5){
						_html.push("发送至："+_display_users.join("、")+"等"+index+"人");
					}else{
						_html.push("发送至："+_display_users.join("、"));
					}
					_html.push('</div>');
					
					_html.push('<div class="btns_wrap reply_btns_wrap">\
								<div class="reply_img"></div>\
								<div class="fl">');
					_html.push(post.comments_num);
					_html.push('条回复</div>\
								<div class="klearboth"></div>\
							</div>');
				
					_html.push('<div class="show_btns statistic_wrap"><div class="statistic"></div><div class="fl">统计</div></div>');
//					_html.push('<div class="show_btns resend_wrap"><div class="resend"></div><div class="fl">重发</div></div>');
					_html.push('</div>\
							<div class="klearboth"></div>');
					
					_html.push('<div class="post_footer hide">\
							<div class="footer_arrow"></div>\
							<input type="text" class="footer_input">\
							<div class="footer_send_btn" parent="0" data="public_');
					_html.push(post.id);
					_html.push('" onclick="iwk_community.comment_send(this);">发&nbsp;送</div>');
					_html.push('<div class="klearboth"></div>');
					_html.push('<a class="comment_attach" id="comment_attach_');
					_html.push(post.id);
					_html.push('"></a>');
					_html.push('<div class="community_comment_attach_queue" id="comment_attach_queue_'+post.id+'"></div>');
					_html.push('<div class="klearboth"></div>');
					_html.push('<ul class="reply_list">');
					_html.push(iwk_community.init_comment_html(post.comments));
					_html.push('</ul>\
							<div class="toggle_replay_wrap">\
								<div class="toggle_detail">收起</div>\
								<div class="up_arrow"></div>\
								<div class="klearboth"></div>\
							</div>\
						</div>\
					</div>');
					
					_html.push('</li>');
					break;
				case 'EXP_SURVEY':
					_html.push('<li data="');
					_html.push(post.id);
					_html.push('" class="li_survey">');
					_html.push(iwk_community.init_send_range(post));
					_html.push('<div class="show_cover_wrap exp_img survey_img">\
							</div>');
					_html.push('<div class="show_content_wrap">\
							<div class="show_content_title">调查问卷</div>\
							<div class="show_content">');
					_html.push(post.content);
					_html.push('</div>');
					_html.push('<div class="klearboth"></div>');
					if(post.has_attachment){
						_html.push('<div class="attachs"><div class="attach_images klear" style="width:100%;">');
						for(var j = 0;j< post.attachment['image'].length;j++){
							_image =  post.attachment['image'][j];
							_pre = 0;
							_next = 0;
							if(j>0){
								_pre = 1;
							}
							if(j+1<post.attachment['image'].length){
								_next = 1;
							}
							_html.push('<a href="javascript:;" attach_id="'+_image.attachment_id+'" data="'+''+'inside/getattachment/id:'+_image.attachment_id+'" class="attach_image first" onclick="iwk_post.view_img_attach(this,'+_pre+','+_next+');">\
									<img src="'+''+'inside/get_file/id:'+_image.attachment_id+'">\
									</a>');
						}
						_html.push('</div>');
						
						for(var j = 0;j < post.attachment['file'].length;j++){
							_file =  post.attachment['file'][j];
							_html.push('<div class="attach_file '+_file.file_type+'" attach_id="'+_file.attachment_id+'" onclick="iwk_post.view_file_attach(this);" data="'+''+'inside/getattachment/id:'+_file.attachment_id+'">');
							_html.push('<a href="javascript:;" title="'+_file.title+'" >'+_file.title+'</a>');
							_html.push('</div>');
						}
						
						for(var j = 0;j < post.attachment['sound'].length;j++){
							_sound =  post.attachment['sound'][j];
							_html.push('<a href="javascript:;" onclick="iwk_priv.play_audio('+''+'inside/getfile/aid:'+_sound.attachment_id+', this, event)" class="attach_sound_play"></a>');
						}
						_html.push('</div>');
					}
					_html.push('<div class="klearboth"></div>\
						</div><div class="klearboth"></div>\
						<div class="show_vote_detail">\
							<div class="cont">展开</div>\
							<div class="down_arrow"></div>\
						</div><div class="vote_detail hide">');
					
					if(post.survey_result.length != 0){
						var question_index = 0;
						for(var n in post.survey_result ){
							var _question = post.survey_result[n];
							var _options = post.questions[question_index];
							var _type;
							if(_options.type == 2){
								_type = 3;
							}else{
								if(_options.option_type == 1){
									_type = 1;
								}else{
									_type = 2;
								}
							}
							_html.push('<div class="isvw_wrap" ques_type ="'+_type+'">\
							<div class="isvw_ttl">');
						_html.push('问题'+(question_index+1)+"："+_options.content);
						_html.push('</div>');
							var _index = 0;
							var is_subjective = 0;
							var _id;
							for(var k in _options.options){
								_id = _options.options[k].id;
							}
							if(_options.type == '2'){
								
								_html.push('<ul class="other_detail_ul">');
								var other_idx = 1;
								for(var p in _question[_id]){
									_html.push('<li class="other_detail">'+other_idx+++'、'+_question[_id][p].content+'['+post.send_customer[p].fullname+']</li>');
								}
								_html.push('</ul>');
								
							}else{
								_html.push('<div class="isvw_options">');
								
								var _sum = 0;
								var options_counts = {};
								for(var n in _options.options){
									var _option = _question[n];
									var option_count = 0;
									for(var j in _option){
										option_count++;
									}
									options_counts[n] = option_count;
									_sum += option_count;
								}
								for(var k in _options.options){
									var _count = options_counts[k];
									_html.push('<div class="isvw_option">\
										<div class="widget_radio disabled">\
											<span class="checked"></span>\
										</div><span class="margin_r">'+iwk_community.abc[_index++]+'</span>');
									_html.push('<span class="option_content">'+ (_options.options[k].content==""?"其他":_options.options[k].content)+'</span>');
									_html.push('</div>');
									_html.push('<div class="isvw_rate_block">\
										<div class="isvw_rate_wrap">\
											<div class="isvw_rate" style="width:');
									_html.push(parseInt(_count/_sum*100));
									_html.push('%;"></div>\
										</div>\
										<span class="isvw_rate_val">');
									_html.push(_count+" ("+parseInt(_count/_sum*100)+"%)");
									_html.push('</span>\
										<div class="klear"></div>\
									</div>');
									is_subjective = _options.options[k].is_subjective;
									_id = _options.options[k].id;
								}
								if(is_subjective){//如果是存在主观回答
									_html.push('<div class="show_other" onclick="iwk_community.toggle_other(this)">查看其他值</div>');
									_html.push('<ul style="list-style-type: none; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px;display:none; ">');
									var other_idx = 1;
									for(var p in _question[_id]){
										_html.push('<li class="other_detail">'+other_idx+++'、'+_question[_id][p].content+'['+post.send_customer[p].fullname+']</li>');
									}
									_html.push('</ul>');
								}
								_html.push("</div>");
							}
							question_index++;
							_html.push("</div>");
						}
					}else{
						var question_index = 0;
						for(var n in post.questions ){
							var _options = post.questions[question_index];
							_html.push('<div class="isvw_wrap">\
								<div class="isvw_ttl">');
							_html.push('问题'+(question_index+1)+"："+_options.content);
							_html.push('</div>\
								<div class="isvw_options">');
							var _index = 0;
							for(var n in _options.options){
								_html.push('<div class="isvw_option">\
									<div class="widget_radio disabled">\
										<span class="checked"></span>\
									</div><span class="margin_r">'+iwk_community.abc[_index++]+'</span>');
								_html.push('<span class="option_content">'+( _options.options[n].content==""?"其他":_options.options[n].content)+'</span>');
								_html.push('</div>');
								_html.push('<div class="isvw_rate_block">\
									<div class="isvw_rate_wrap">\
										<div class="isvw_rate" style="width:');
								_html.push(0);
								_html.push('%;"></div>\
									</div>\
									<span class="isvw_rate_val">');
								_html.push(0+" ("+0+"%)");
								_html.push('</span>\
									<div class="klear"></div>\
								</div>');
							}
							_html.push("</div></div>");
							question_index++;
						}
					}
					
					_html.push('</div>');
					_html.push('<div class="show_content_footer">\
					<div class="show_footer1">');
					post.post_date = new Date(Number(post.post_date)*1000);
					_html.push(post.post_date.getFullYear()+"年"+(post.post_date.getMonth()+1)+"月"+post.post_date.getDate()+"日 "+(post.post_date.getHours())+":"+(post.post_date.getMinutes()<10?'0'+post.post_date.getMinutes():post.post_date.getMinutes()));
					var _users = [];
					var _display_users = [];
					var index = 0;
					for(var j in post.send_customer){
						index++;
						_users.push(post.send_customer[j].fullname);
						if(index <=5){
							_display_users.push(post.send_customer[j].fullname);
						}
					}
					for(var j in post.send_workers){
						index++;
						_users.push(post.send_workers[j].fullname);
						if(index <=5){
							_display_users.push(post.send_workers[j].fullname);
						}
					}
					_html.push('</div>\
							<div class="show_footer2" title ='+_users.join("、")+'>');
					if(_users.length > 5){
						_html.push("发送至："+_display_users.join("、")+"等"+index+"人");
					}else{
						_html.push("发送至："+_display_users.join("、"));
					}
					_html.push('</div>');
					
					_html.push('<div class="btns_wrap reply_btns_wrap">\
								<div class="reply_img"></div>\
								<div class="fl">');
					_html.push(post.comments_num);
					_html.push('条回复</div>\
								<div class="klearboth"></div>\
							</div>');
					
					_html.push('<div class="show_btns statistic_wrap"><div class="statistic"></div><div class="fl">统计</div></div>');
//					_html.push('<div class="show_btns resend_wrap"><div class="resend"></div><div class="fl">重发</div></div>');
					_html.push('<div class="show_btns show_survey_wrap"><div class="show_result"></div><div class="fl">导出结果</div></div>');
					_html.push('</div>\
							<div class="klearboth"></div>');
					
					_html.push('<div class="post_footer hide">\
							<div class="footer_arrow"></div>\
							<input type="text" class="footer_input">\
							<div class="footer_send_btn" parent="0" data="public_');
					_html.push(post.id);
					_html.push('" onclick="iwk_community.comment_send(this);">发&nbsp;送</div>');
					_html.push('<div class="klearboth"></div>');
					_html.push('<a class="comment_attach" id="comment_attach_');
					_html.push(post.id);
					_html.push('"></a>');
					_html.push('<div class="community_comment_attach_queue" id="comment_attach_queue_'+post.id+'"></div>');
					_html.push('<div class="klearboth"></div>');
					_html.push('<ul class="reply_list">');
					_html.push(iwk_community.init_comment_html(post.comments));
					_html.push('</ul>\
							<div class="toggle_replay_wrap">\
								<div class="toggle_detail">收起</div>\
								<div class="up_arrow"></div>\
								<div class="klearboth"></div>\
							</div>\
						</div>\
					</div>');
					
					_html.push('</li>');
					break;
				}
			}
			if(_from == "init"){
				if(_status && _status == 0){
					$("#community_show").hide();
					$("#community_collection").html(_html.join("")).show();
					if(list_count>$("#community_collection li").length){
						$(".iwk_more_loader").show();
					}else{
						$(".iwk_more_loader").hide();
					}
				}else{
					$("#community_collection").hide();
					$("#community_show").html(_html.join("")).show();
					if(list_count>$("#community_show li").length){
						$(".iwk_more_loader").show();
					}else{
						$(".iwk_more_loader").hide();
					}
				}
			}else if(_from == 'save'){
				if(_status == 0){
	//				$("#saved_tab").click();
					zebra_alert("保存成功");
					$("#community_collection").prepend(_html.join(""));
					fancylay.unblock();
				}else{
	//				$("#sended_tab")
					zebra_alert("发送成功");
					$("#community_show").prepend(_html.join(""));
					fancylay.unblock();
				}
			}else{
				if(_status && _status == 0){
					$("#community_show").hide();
					$("#community_collection").html($("#community_collection").html()+_html.join("")).show();
					if(list_count>$("#community_collection li").length){
						$(".iwk_more_loader").show();
					}else{
						$(".iwk_more_loader").hide();
					}
				}else{
					$("#community_collection").hide();
					$("#community_show").html($("#community_show").html()+_html.join("")).show();
					if(list_count>$("#community_show li").length){
						$(".iwk_more_loader").show();
					}else{
						$(".iwk_more_loader").hide();
					}
				}
			}
			$(".community_body_wrap ul li .show_content img").hide();
		},
		registrate : function(){
			var post_id = $(this).parents("li").attr("data");
			window.location.href = ''+"apps/community/attend_record/post_id:"+post_id;
		},
		end_meeting : function(){
			var $this = $(this);
			var post_id = $this.parents("li").attr("data");
			$.post(''+"inside/community/from:end_meeting/post_id:"+post_id,function(res){
				if(res.status){
					zebra_alert("关闭会议成功");
					$this.remove();
				}else{
					zebra_alert("关闭会议失败");
				}
			},'json');
		},
		toggle_other : function(_this){
			$(_this).next().slideToggle();
		},
		toggle_vote : function(){
			var _this = $(this);
			$(this).next().slideToggle(400,function(){
				if(_this.find("div.down_arrow").length == 0){
					_this.find("div.cont").html("展开").next().removeClass().addClass("down_arrow");
				}else{
					_this.find("div.cont").html("收起").next().removeClass().addClass("up_arrow");
				}
			});
		},
		select_single_detail:function(){
			$(this).addClass("selected").siblings().removeClass("selected");
			$(this).siblings(".other").next().remove();
		},
		select_multi_detail:function(){
			$(this).toggleClass("selected");
		},
		select_other_detail:function(){
			var $this = $(this);
			if($this.is(".selected")){
				if($this.next().length != 0){
					return;
				}
				$this.after('<div class=""><div class="widget_ipt_lite_wrap" style="width:300px;margin-left:10px;">\
						<input type="text" class="widget_ipt_lite" style="width:300px;" value="">\
						</div></div>').next().find("input").focus()
			}else{
				$this.next().remove();
			}
		},
		toggle_survey_type : function(_this){
			$this = $(_this).parents("div.pf_survey_type1");
			if($(_this).attr("data") == 2){
				$this.next().hide().next().hide().next().hide();
				$this.parent().next().hide().next().hide().next().hide();
			}else{
				$this.next().show().next().show().next().show();
				$this.parent().next().show().next().show().next().show();
			}
		},
		toggle_statistic : function(){
			$("body").click();
			$this = $(this);
			var _top = $this.offset().top+$this.height()-39;
			$("#show_statistic").css({top:_top,right:0}).show();
			var _post_id = $this.parents("li").attr("data");
			if($this.parents("li").attr("class") == "li_notice"){
				$("#stastic_type").val(1);
			}else if($this.parents("li").attr("class") == "li_meeting"){
				$("#stastic_type").val(2);
			}else{
				$("#stastic_type").val(0);
			}
			$("#show_stastic_detail").attr("post_id",_post_id);
			if($this.attr("is_sms") == "1"){
				var _checkbox = $("#show_statistic").find(".mse_checkbox");
				_checkbox.find(">span").attr("class","checked");
				_checkbox.find("input").val("1").prop("checked",true);
			}else{
				var _checkbox = $("#show_statistic").find(".mse_checkbox");
				_checkbox.find(">span").removeClass();
				_checkbox.find("input").val("0").prop("checked",false);
			}
			$.post( '' + "inside/community/from:get_rate/post_id:"+_post_id+"/r:" + Math.round(Math.random() * 1000), function(res) {
				var $stas = $("#show_statistic");
				$stas.find(".total_num").html(res.total_num);
				$stas.find(".click_num").html(res.click_num);
				$stas.find(".click_rate").html(res.click_rate);
				$stas.find(".unclick_num").html(res.unclick_num);
				$stas.find(".unclick_rate").html(res.unclick_rate);
				$("#resend").attr("onclick","iwk_community.resend('"+res.unclick_num+"','"+_post_id+"')");
				$('#statistic_pie').highcharts({
					credits: {
						enabled: false
					},
					chart: {
						type: 'line'
					},
			        title: {
			            text: ''
			        },
					tooltip: {
			            crosshairs: true,
			            shared: true
			        },
			        plotOptions: {
	                    pie: {
	                        allowPointSelect: true,
	                        cursor: 'pointer',
	                        dataLabels: {
	                            enabled: false
	                        }
	                    }
	                },
					series: [{
			            type: 'pie',
			            name: '数量',
			            data: [
			                {
			                    name: '点击量',
			                    y: res.click_num,
			                    color:"#498e00"
			                },
			                {
			                    name: '未点击量',
			                    y: res.unclick_num,
			                    color:"#ff9300"
			                },
			            ]
			        }]
				});
				if(res.can_resend){
					$stas.find(".footer").slideDown();
				}
			},'json');
			return false;
		},
		toggle_replay : function(){
			iwk_cfg_comment.temp_id = iwk_common.get_new_guid();
			iwk_community_pop.comment_uploadify($('#comment_attach_'+$(this).closest("li").attr("data")+''), 'comment_attach_queue_'+$(this).closest("li").attr("data"));
			$(this).parents(".show_content_footer").nextAll(".post_footer").slideToggle(400).next(".post_detail").hide();
		},
		comment_send:function(_this){
			var _pid = $(_this).attr("data");
			var _parent_data = $(_this).attr("parent");
			var _textarea = $(_this).prev();
			var _msg = $.trim(_textarea.val());
			var $ul = $(_this).closest(".post_footer").find(".reply_list");
			var upload_list = $(_this).closest(".post_footer").find(".community_comment_attach_queue");
			if($(_this).attr("parent") != 0){
				_msg = _msg.replace(/^回复\s[^：.*]*：/,"");
			}
			var _parent = $(_this).closest("div.post_footer");
			var _data = {
				parent : _parent_data,
				postid : _pid,
				message : _msg,
				post_temp_id : iwk_cfg_comment.temp_id
			};

			if (_msg === "") {
				zebra_alert(iwk_lng.post_empty_comment);
				return;
			}
			if (iwk_cfg_comment.attach_sending) {
				zebra_alert(iwk_lng.attach_is_sending_msg);
				return;
			}
			if (iwk_cfg_comment.sending) {
				zebra_alert(iwk_lng.is_sending_msg);
				return;
			}

			_textarea.attr("disabled", "disabled");
			$(_this).attr("disabled", "disabled");

			iwk_cfg_comment.sending = 1;
			var _guid = $("#guid_hid").val();
			$.post('' + 'ajax/comment_community_ins'+'/r:'
					+ Math.round(Math.random() * 1000), _data, function(res) {
				if (res.status.toLowerCase() == "ok") {
					_html = [];
					if(res.parent == 0){
						var _comment = JSON.parse(res.comment_cont);
						_html.push('<li comment_id="');
						_html.push(_comment.comment_id);
						_html.push('">\
								<img class="reply_photo" alt="" src="');
						_html.push(_comment.user_photo);
						_html.push('">');
						_html.push('<div class="reply_content">');
						_html.push('<div class="reply_user">');
						_html.push(_comment.name);
						_html.push('</div>');
						_html.push(_comment.comment_message);
						_html.push('<div class="reply_time">');
						_html.push(iwk_date.formatFullDate(new Date(Number(_comment.date)*1000)));
						_html.push('</div>');
						_html.push('</div>\
								<div class="reply" c_name="');
						_html.push(_comment.name);
						_html.push('" parent="');
						_html.push(_comment.comment_id);
						_html.push('">回复</div>\
								<div class="klearboth"></div>');
						if(_comment.attachment){
							_html.push('<div class="attachs"><div class="attach_images klear" style="width:100%;">');
							for(var j = 0;j< _comment.attachment['image'].length;j++){
								_image =  _comment.attachment['image'][j];
								_pre = 0;
								_next = 0;
								if(j>0){
									_pre = 1;
								}
								if(j+1<_comment.attachment['image'].length){
									_next = 1;
								}
								_html.push('<a href="javascript:;" data="'+''+'inside/getattachment/id:'+_image.attachment_id+'" class="attach_image first" onclick="iwk_post.view_img_attach(this,'+_pre+','+_next+');">\
										<img src="'+''+'inside/get_file/id:'+_image.attachment_id+'">\
										</a>');
							}
							_html.push('</div>');
							
							for(var j = 0;j < _comment.attachment['file'].length;j++){
								_file =  _comment.attachment['file'][j];
								_html.push('<div class="attach_file '+_file.file_type+'" onclick="iwk_post.view_file_attach(this);" data="'+''+'inside/getattachment/id:'+_file.attachment_id+'">');
								_html.push('<a href="javascript:;" title="'+_file.title+'" >'+_file.title+'</a>');
								_html.push('</div>');
							}
							_html.push('</div>');
						}
							_html.push('</li>');
							$ul.append(_html.join(""));
					}else{
						var _recomment = JSON.parse(res.comment_cont);
						_html.push('<div class="recomment">');
						_html.push('<img class="reply_photo" src="');
						_html.push(_recomment.user_photo);
						_html.push('">');
						_html.push('<div class="reply_content">');
						_html.push('<div class="reply_user">');
						_html.push(_recomment.name);
						_html.push('</div>');
						_html.push(_recomment.comment_message);
						_html.push('<div class="reply_time">');
						_html.push(iwk_date.formatFullDate(new Date(Number(_recomment.date)*1000)));
						_html.push('</div>');
						_html.push('</div>');
						_html.push('<div class="klearboth"></div>');
						
						if(_recomment.attachment){
							_html.push('<div class="attachs"><div class="attach_images klear" style="width:100%;">');
							for(var j = 0;j< _recomment.attachment['image'].length;j++){
								_image =  _recomment.attachment['image'][j];
								_pre = 0;
								_next = 0;
								if(j>0){
									_pre = 1;
								}
								if(j+1<_recomment.attachment['image'].length){
									_next = 1;
								}
								_html.push('<a href="javascript:;" data="'+''+'inside/getattachment/id:'+_image.attachment_id+'" class="attach_image first" onclick="iwk_post.view_img_attach(this,'+_pre+','+_next+');">\
										<img src="'+''+'inside/get_file/id:'+_image.attachment_id+'">\
										</a>');
							}
							_html.push('</div>');
							
							for(var j = 0;j < _recomment.attachment['file'].length;j++){
								_file =  _recomment.attachment['file'][j];
								_html.push('<div class="attach_file '+_file.file_type+'" onclick="iwk_post.view_file_attach(this);" data="'+''+'inside/getattachment/id:'+_file.attachment_id+'">');
								_html.push('<a href="javascript:;" title="'+_file.title+'" >'+_file.title+'</a>');
								_html.push('</div>');
							}
							_html.push('</div>');
						}
						_html.push('</div>');
						_html.push('<div class="klearboth"></div>');
						$ul.find("li[comment_id='"+_recomment.parent+"']").append(_html.join(""));
					}
					$(_this).attr("parent",0);
					iwk_post.init_comment_cfg();
					upload_list.empty();
					
					iwk_cfg_comment.sending = 0;
					_textarea.val("").removeAttr("disabled");
				} else {
					zebra_alert(res.message);
					iwk_cfg_comment.sending = 0;
					_textarea.removeAttr("disabled");
				}
			}, 'json');
		},
		confirm_select : function(){
			var ias = $('#image_select').imgAreaSelect({ instance: true });
			$("#imgselected_data").val(JSON.stringify(ias.getSelection()));

			var _data = {};
			_data.image_select = $('#image_select').attr("data");
			_data.imgselected_data = $("#imgselected_data").val();
			$.post(''+"ajax/community_upload_select",_data,function(res){
				if(res != "ERR"){
					$("#"+$("#upload_type").val()).html("<div class='photo_img_wrap'><img id='"+$("#upload_type").val()+"_photo_img' class='photo_img'  data='"+res[0]+"' src='"+res[1]+"' ></div>");
				}
			},'json')

			ias.cancelSelection();
			$.fancybox.close();
		},
		morer_wrap : function(_this){
			if($(_this).find("a").find(".spinner").is(":visible")){
				return;
			}
			$(_this).find("a").find(".spinner").show();
			var _len = $("#community_show>li").length;
			var _status = $(".list_tab.focus").attr("tab_status");
			if(_status == 0){
				_len = $("#community_collection>li").length;
			}
			$.post(''+"inside/community/from:ajax/start_from:"+_len,{status:_status},function(res){
				iwk_community.init_post_list(res,_status);
				$(_this).find("a").find(".spinner").hide();
			},'json');
		},
		resend_vote : function(){
			$("#tab_vote").click();
			var $this = $(this);
			var $parent = $this.closest("li");
			var _content = $parent.find(".show_content").html();
			var send_range_hid = $parent.find(".post_send_range").val();
			var send_range = $parent.find(".show_footer2").html().replace("发送至：","");
			if($parent.find(".attachs").length != 0){
				var _attachs = $parent.find(".attachs").get(0).outerHTML;
			}
			
			$(".send_range_vote").val(send_range);
			$("#range_hid_vote").val(send_range_hid);
			$("#vote_textarea").val(_content);

			$("#vote_attachs").remove();
			if(_attachs){
				$("#vote_btns").after("<li id='vote_attachs'>"+_attachs+"</li>");
			}
			
			var $options = $parent.find(".isvw_option .option_content");
			var _len = $options.length;
			var $option_lines = $("#community_vote").find(".vote_option_line");
			if($option_lines.length < _len){
				for(var i = $option_lines.length;i < _len;i++){
					$("#add_vote_option").click();
				}
			}else{
				for(var i = _len;i < $option_lines.length;i++){
					$($option_lines[i]).find(".vote_del").click();
				}
			}
			$option_lines = $("#community_vote").find(".vote_option_line");
			for(var i = 0;i < _len;i++){
				$($option_lines[i]).find(".vote_write_input").val($($options[i]).html());
			}
			$("#vote_textarea").focus();
		},
		resend_survey : function(){
			$("#tab_survey").click();
			var $this = $(this);
			var $parent = $this.closest("li");
			var _content = $parent.find(".show_content").html();
			var send_range_hid = $parent.find(".post_send_range").val();
			var send_range = $parent.find(".show_footer2").html().replace("发送至：","");
			if($parent.find(".attachs").length != 0){
				var _attachs = $parent.find(".attachs").get(0).outerHTML;
			}
			
			$(".send_range_survey").val(send_range);
			$("#range_hid_survey").val(send_range_hid);
			$("#survey_textarea").val(_content).focus();

			$("#survey_attachs").remove();
			if(_attachs){
				$("#survey_btns").after("<li id='survey_attachs'>"+_attachs+"</li>");
			}
			
			var $questions = $parent.find(".isvw_wrap");
			var questions_len = $questions.length;
			var $questions_show = $("#community_survey .survey_question_wrap");
			var questions_show_len = $questions_show.length;
			
			if(questions_len < questions_show_len){
				for(var i = questions_len;i < questions_show_len;i++){
					$questions_show[i].find(".widget_close_question_wrap").click();
				}
			}else{
				for(var i = questions_show_len;i < questions_len;i++){
					$("#add_question").click();
				}
			}
			
			$questions_show = $("#community_survey .survey_question_wrap");
			for(var m = 0;m < $questions_show.length;m++){
				var $options = $($questions[m]).find(".isvw_option .option_content");
				var $options_show = $($questions_show[m]).find(".option_line");
				var options_len = $options.length;
				var options_show_len = $options_show.length;
				
				$($questions_show[m]).find(".survey_write_ques").val($($questions[m]).find(".isvw_ttl").html());
				
				if(options_len < options_show_len){
					for(var i = options_len;i < options_show_len;i++){
						$options_show[i].find(".survey_del").click();
					}
				}else{
					for(var i = options_show_len;i < options_len;i++){
						$($questions_show[m]).find(".add_survey_option").click();
					}
				}
				
				$options_show = $($questions_show[m]).find(".option_line");
				for(var i = 0,_len = $options_show.length;i < _len;i++){
					$($options_show[i]).find(".survey_write_input").val($($options[i]).html());
				}
			}
		},
		animate_tablist : function(){
			$(".iwk_more_loader").hide();
			$(this).removeClass().addClass("list_tab focus").siblings().removeClass("focus")
			$(".list_tab_wrap i").animate({left:$(this).attr("tab_left")},300);
			fancylay.block();
			var _status = $(this).attr("tab_status");
			$.post(''+'inside/community/from:ajax'+"/r:" + Math.round(Math.random() * 1000),{status:_status},function(res){
				iwk_community.init_post_list(res,_status,'init');
				fancylay.unblock();
			},'json');
		},
		edit_post : function(){
			if(!editor){
				zebra_alert("请等待编辑器初始化完成");
				return;
			}
			var $this = $(this);
			var $parent = $this.closest("li");
			var _title = $parent.find(".show_content_title").html();
			var _content = $parent.find(".show_content").html();
			var _photo = $parent.find(".show_cover").attr("src");
			var send_range_hid = $parent.find(".post_send_range").val();
			var send_range = $parent.find(".show_footer2").html().replace("发送至：","");
			if($parent.find(".attachs").length != 0){
				var _attachs = $parent.find(".attachs").get(0).outerHTML;
			}
			
			$("#notice_title").val(_title).focus();
			$("#send_range_input").val(send_range);
			$("#range_hid_notice").val(send_range_hid);
			editor.html(_content);
			
			if(_photo){
				var photo_contents = _photo.split("\/");
				var _photo_id = photo_contents[photo_contents.length-1];
				$("#upload_content #upload_content-button").html("<div class='photo_img_wrap'><img id='"+$("#upload_type").val()+"_photo_img' class='photo_img'  data='"+""+"' src='"+_photo+"' ></div>");
			}

			$("#notice_attachs").remove();
			if(_attachs){
				$("#li_btns").after("<li id='notice_attachs'>"+_attachs+"</li>");
				var _imgs = $("#notice_attachs").find("a.attach_image");
				for(var i = 0;i < _imgs.length;i++){
					$(_imgs[i]).append('<div class="attach_toggle selected" onclick="iwk_community.attach_toggle(this,event)"></div>').addClass("selected");
				}
				$("#notice_attachs").find(".attach_file").addClass("selected").before('<div class="attach_file_toggle selected" onclick="iwk_community.attach_file_toggle(this,event)"></div>').after('<div class="klearboth"></div>');
			}
			$("#save_type").val($parent.attr("data"));
			$(".community_body").hide();
			$("#community_notice").show();
			$("#banner_focus").animate({left:15},300);
		},
		del_post : function(){
			var $li = $(this).closest("li");
			zebra_confirm('确定删除吗？',function(){
				fancylay.block();
				var post_id = $li.attr("data");
				$.post( '' + "inside/community/from:del_post/post_id:"+post_id+"/r:" + Math.round(Math.random() * 1000), function(res) {
					if(res){
						fancylay.unblock();
						zebra_auto("删除成功");
						$li.slideUp();
					}else{
						zebra_alert("不允许删除");
						fancylay.unblock();
					}
				},'json');
			});
		},
		attach_toggle : function(_this,e){
			$(_this).toggleClass("selected").parent().toggleClass("selected");
			iwk_common.stop_propagation(e);
			return false;
		},
		attach_file_toggle : function(_this,e){
			$(_this).toggleClass("selected").next().toggleClass("selected");
			iwk_common.stop_propagation(e);
			return false;
		},
		show_stastic_detail : function(_this){
			fancylay.block();
			var post_id = $(_this).attr("post_id");
			var stastic_type = $("#stastic_type").val();
			window.location.href =  '' + "inside/comu_post_detail/post_id:"+post_id+"/stastic_type:"+stastic_type;
		},
		show_watched : function(_url){
			fancylay.block();
			var post_id = $("#post_id").val();
			_url = typeof _url == 'string'?_url:'' + "inside/comu_post_detail/from:show_watched/post_id:"+post_id+'/r:' + Math.round(Math.random() * 1000);
			$.post(_url, function(res) {
				$("#watched").addClass("focus").siblings().removeClass("focus");
				$("#post_body").html(res);
				fancylay.unblock();
			},'html');
		},
		show_unwatch : function(_url){
			fancylay.block();
			var post_id = $("#post_id").val();
			_url = typeof _url == 'string'?_url:'' + "inside/comu_post_detail/from:show_unwatch/post_id:"+post_id+"/stastic_type:"+$("#stastic_type").val()+'/r:' + Math.round(Math.random() * 1000);
			$.post(_url, function(res) {
				$("#unwatch").addClass("focus").siblings().removeClass("focus");
				$("#post_body").html(res);
				fancylay.unblock();
			},'html');
		},
		show_survey_detail : function(){
			var _data = {};
			var $wrap = $(this).closest("li.li_survey");
			_data.title = $wrap.find(".show_content").html();
			_data.questions = [];
			var $questions = $wrap.find(".isvw_wrap");
			for(var i = 0;i < $questions.length;i++){
				$question = $($questions[i]);
				_question = {};
				_question.type = $question.attr("ques_type");
				_question.title = $question.find(".isvw_ttl").html();
				_question.options = [];
				if($question.find(".isvw_rate_wrap").length == 0){
					var $options = $question.find(".other_detail");
					for(var j = 0;j < $options.length;j++){
						var _option = {};
						var _content = $($options[j]).html().split(/\w*、/)[1];
						var _user = _content.match(/\[\W*\]/)[0];
						_option.content = _content.replace(_user,"");
						_option.user = _user.substr(1,_user.length-2);
						_question.options.push(_option);
					}
				}else{
					var $options = $question.find(".isvw_option");
					for(var j = 0;j < $options.length;j++){
						var _option = {};
						_option.content = $($options[j]).find(".option_content").html();
						_option.count = $($options[j]).next().find(".isvw_rate_val").html();
						_question.options.push(_option);
					}
				}
				_data.questions.push(_question);
			}
			$("#submit_data").val(JSON.stringify(_data));
			$("#submit_survey_excel").submit();
		},
		resend : function(_count,post_id){
			var _data = {};
			_data.count = _count;
			_data.post_id = post_id?post_id:$("#post_id").val();
			_data.is_sms = $("#is_sms_post").prop("checked")?1:0;
			$.post(''+"inside/community/from:resend",_data,function(res){
				if(res.status == "sms_not"){
					zebra_confirm("当前短信不足，无法发送短信，是否继续？",function(){
						$("#is_sms_post").prop("checked",false);
						iwk_community.resend(_count);
					});
				}else{
					zebra_alert(res.msg);
				}
			},'json');
		},
		toggle_send_range : function(_this){
			var $this = $(_this);
			if($this.find(">span").is(".checked")){
				$this.parents("li").find(".title").html("选择会议：");
				$("#range_hid_notice").val("");
				$("#send_range_input").val("").attr("placeholder","请点击选择会议");
				$this.prev(".send_range").unbind("click").bind("click",function(){
					iwk_community.pop_meeting();
			     });
			}else{
				$this.parents("li").find(".title").html("发送范围：");
				$("#send_range_input").val("").attr("placeholder","请点击选择发送范围");
				$("#meeting_val").val("");
				$this.prev(".send_range").unbind("click").bind("click",function(){
					iwk_community.pop_users();
			     });
			}
		},
		pop_meeting : function(){
			fancylay.block();
			$.post( '' + "inside/community/from:"+"query_meeting"+"/r:" + Math.round(Math.random() * 1000), function(res) {
				var $ul = $("#meeting_list_ul");
				var _html = [];
				for(var i = 0;i < res.length;i++){
					_html.push('<li post_id='+res[i].post_id+'>\
						<div class="radio" style="float:left;margin-top: 6px;">\
							<span><input type="radio" name="pop_meeting"  style="opacity: 0; " onclick="iwk_common.radio_click(this)"></span>\
						</div>\
						<div class="name_list" style="float:left;">'+res[i].message+'</div>\
						<div class="klearboth"></div>\
					</li>');
				}
				if(_html.length == 0){
					$ul.html('<div style="height:100px;line-height:100px;text-align:center;font-size:15px;margin-left:-20px;color:#555;">没有可选会议</div>');
				}else{
					$ul.html(_html.join(""));
				}
				fancylay.unblock();
				$.fancybox({
		    		modal: true,
		    		href: "#meeting_list",
		    		helpers: {overlay: {opacity: 0.2}},
		    		padding:0,
		    		beforeLoad: function(){
		    		}
		    	});
			},'json');
		},
		confirm_meeting : function(){
			var $ul = $("#meeting_list_ul");
			var post_id = $ul.find("input:checked").parents("li").attr("post_id");
			$("#meeting_val").val(post_id);
			$("#send_range_input").val($ul.find("input:checked").parents("li").find(".name_list").html());
			$.fancybox.close();
		},
		cancel_meeting : function(){
			$.fancybox.close();
		}
};

var iwk_community_pop = {
		toggle_detail_wrap : function(){
			var _time = 800;
			var _parent = $(this).parents(".post_content_wrap");
			var _img = _parent.find(".content_cover");
			var img_wrap = _parent.find(".content_cover_wrap");
			var _content = _parent.find(".content_text_wrap");
			var toggle_btn = _parent.find(".toggle_detail");
			var arrow_btn = _parent.find(".arrow_btn");
			if(_content.is(".content_narrow")){
				_content.hide().removeClass("content_narrow").addClass("content_wide");
				_img.css({'max-width':500,'max-height':360});
				img_wrap.css({'width':500,'height':360});
				_content.slideDown(_time,function(){
					toggle_btn.text("收起");
					arrow_btn.removeClass("down_arrow").addClass("up_arrow");
				});
			}else{
				_content.slideUp	(_time,function(){
					_content.removeClass("content_wide").addClass("content_narrow").show();
					toggle_btn.text("展开");
					arrow_btn.removeClass("up_arrow").addClass("down_arrow");
				});
				_img.animate({'width':164,'height':110},_time);
			}
		},
		toggle_detail_wrap2:function(){	
			var _time = 800;
			var _li = $(this).closest(".post_line");
			var _parent = $(this).parents(".post_content_wrap");
			var _img = _parent.find(".content_cover");
			var img_wrap = _parent.find(".content_cover_wrap");
			var _content = _parent.find(".content_text_wrap");
			var toggle_btn = _parent.find(".toggle_detail");
			var arrow_btn = _parent.find(".arrow_btn");
			var post_content = _parent.find(".post_content");
			var $attach = _parent.find(".attachs");
			if(_content.is(".content_narrow")){
				_li.find(".content_title").addClass("title_wide");
				_content.removeClass("content_narrow").addClass("content_wide");
				_img.addClass("content_cover_external");
				img_wrap.addClass("community_img_common");
				$attach.addClass("wide");
				$(".community_pop_body .post_line .content_text_wrap img").show();
				toggle_btn.text("收起");
				arrow_btn.removeClass("down_arrow").addClass("up_arrow");
				$("html,body").animate({scrollTop:_li.position().top},800);
			}else{
				_li.find(".content_title").removeClass("title_wide");
				_content.removeClass("content_wide").addClass("content_narrow");
				_img.removeClass("content_cover_external");
				img_wrap.removeClass("community_img_common");
				$attach.removeClass("wide");
				$(".community_pop_body .post_line .content_text_wrap img").hide();
				toggle_btn.text("展开");
				arrow_btn.removeClass("up_arrow").addClass("down_arrow");
				$("html,body").animate({scrollTop:_li.position().top},800);
			}
		},
		toggle_detail : function(){
			$(this).parents(".post_footer").slideUp(400);
		},
		toggle_replay : function(){
			iwk_cfg_comment.temp_id = iwk_common.get_new_guid();
			iwk_community_pop.comment_uploadify($('#comment_attach_'+$(this).closest(".post_line").attr("post_id")+''), 'comment_attach_queue_'+$(this).closest(".post_line").attr("post_id"));
			$(this).parents(".post_content_wrap").next(".post_footer").slideToggle(400).next(".post_detail").hide();
		},
		comment_uploadify : function(_ipt, _queue_id) {
			_ipt
			.uploadify({
				'checkExisting' : false,
				'swf' : ''
						+ 'themes/art/js/uploadify/uploadify.swf',
				'uploader' : '' + 'ajax/postform_attachupl',
				'uploadLimit' : 0,
				'queueSizeLimit' : 10,
				'width' : '40',
				'height' : '25',
				'buttonClass' : 'iwk_attachment_btn',
				'buttonText' : '',
				'fileObjName' : 'file',
				'fileSizeLimit' : '30MB',
				'queueID' : _queue_id,
				'removeCompleted' : false,
				'itemTemplate' : '<div id="${fileID}" class="uploadify-queue-item" instanceid="${instanceID}" fileid="${fileID}">\
								<div class="cancel">\
									<a href="javascript:iwk_post.remove_comment_attach(\'${instanceID}\', \'${fileID}\')">删除</a>\
								</div>\
								<span class="fileName">${fileName} (${fileSize})</span><span class="data"></span>\
								<div class="uploadify-progress">\
									<div class="uploadify-progress-bar"></div>\
								</div>\
							</div>',
				'method' : 'post',
				'onFallback' : function() {
					// alert('Flash was not detected.');
				},
				'onUploadStart' : function(file) {
					iwk_cfg_comment.attach_sending = 1;
					$('#' + this.settings.id).uploadify('settings',
							'formData', {
								'flag' : file.id,
								'session_id' : iwk_cfg.sid
							});
				},
				'onUploadSuccess' : function(file, data, response) {
					var _url = '' + 'ajax/postcomment_attach';
					$.post(_url, {
						'post_temp_id' : iwk_cfg_comment.temp_id,
						'flag' : file.id
					}, function(res) {
						iwk_cfg_comment.attach_sending = 0;
					});
				},
				'onSelect' : function(file) {
					var _upload_id = this.settings.id;
//					uploadifier_on_select(_upload_id, file.id);
				}
			});
		},
		toggle_post_detai : function(){
			var $this = $(this);
			$(this).next().slideToggle(400,function(){
				if($this.find(".down_arrow").length == 0){
					$this.find(".toggle_detail").html("展开").next().removeClass("up_arrow").addClass("down_arrow");
				}else{
					$this.find(".toggle_detail").html("收起").next().removeClass("down_arrow").addClass("up_arrow");
				}
			});
		},
		init_posts : function($list,_type,company_id){
			if($list[1].length == 0 && $.trim($("#community_pop_body").html())=="" && _type != "meeting_list"){
				$("#community_pop_body").html("<div class='empty_data'>无查询数据</div>");
				return;
			}
			var list_count = $list[0];
			$list = $list[1];
			var $wrap  = $("#community_pop_body");
			var _html = [];
			for(var m = 0;m < $list.length;m++){
				var _post = $list[m];
				var post_company_id = company_id?company_id:_post.company_id;
				switch(_post.type){
				case 'EXP_NOTICE':
					_html.push('<div class="post_line notice_pop" post_id="');
					_html.push(_post.id);
					_html.push('" cid="');
					_html.push(post_company_id);
					_html.push('" id="public_');
					_html.push(_post.id);
					if(_post.meeting_id && _type != "meeting_list"){
						_html.push('" meeting_id = "');
						_html.push(_post.meeting_id);
					}
					_html.push('">');
					_html.push('<div class="post_body">\
							<div class="post_content_wrap">\
							<div class="post_content">');
					if(_post.meeting_id && _type != "meeting_list"){
						if(_post.meeting_cover){
							_html.push('<div class="content_cover_wrap">\
											<img alt="封面" class="content_cover" src="');
							_html.push(_post.meeting_cover);
							_html.push('">\
										</div>');
						}else{
							_html.push('<div class="content_cover_wrap exp_img meeting_img"></div>');
						}
					}else{
						if(_post.photo == ""){
							_html.push('<div class="content_cover_wrap exp_img notice_img"></div>');
						}else{
							_html.push('<div class="content_cover_wrap">\
											<img alt="封面" class="content_cover" src="');
							_html.push(_post.photo);
							_html.push('">\
										</div>');
						}
					}
					_html.push('<div class="content_text_wrap content_narrow">\
									<div class="content_title" title='+_post.title+'>');
					_html.push(_post.title);
					_html.push('</div>\
									<div class="content_text">');
					_html.push(_post.content);
					_html.push('</div>');
					if(_post.meeting_id && _type != "meeting_list"){
						_html.push('<div class="content_meeting_header"></div>');
					}
					_html.push('</div>');
					if(_post.has_attachment){
						_html.push('<div class="attachs"><div class="attach_images klear" style="width:100%;">');
						for(var j = 0;j< _post.attachment['image'].length;j++){
							_image =  _post.attachment['image'][j];
							_pre = 0;
							_next = 0;
							if(j>0){
								_pre = 1;
							}
							if(j+1<_post.attachment['image'].length){
								_next = 1;
							}
							_html.push('<a href="javascript:;" data="'+''+'inside/getattachment/id:'+_image.attachment_id+'/cid:'+post_company_id+'" class="attach_image first" onclick="iwk_post.view_img_attach(this,'+_pre+','+_next+');">\
									<img src="'+''+'inside/get_file/id:'+_image.attachment_id+'/cid:'+post_company_id+'">\
									</a>');
						}
						_html.push('</div>');
						
						for(var j = 0;j < _post.attachment['file'].length;j++){
							_file =  _post.attachment['file'][j];
							_html.push('<div class="attach_file '+_file.file_type+'" >');
							_html.push('<a href="'+''+'inside/getfile/cid:'+post_company_id+'/aid:'+_file.attachment_id+'" target="_blank" title="'+_file.title+'" >'+_file.title+'</a>');
							_html.push('</div>');
						}
						
						for(var j = 0;j < _post.attachment['sound'].length;j++){
							_sound =  _post.attachment['sound'][j];
							_html.push('<a href="javascript:;" onclick="iwk_priv.play_audio('+''+'inside/getfile/aid:'+_sound.attachment_id+', this, event)" class="attach_sound_play"></a>');
						}
						_html.push('</div>');
					}
					_html.push('<div class="klearboth"></div>\
							</div>');
					if(!(_post.meeting_id && _type != "meeting_list")){
						_html.push('<div class="toggle_detail_wrap">\
								<div class="toggle_detail">展开</div>\
								<div class="arrow_btn down_arrow"></div>\
								<div class="klearboth"></div>\
							</div>');
					}
					_html.push('<div class="post_content_footer">\
								<div class="post_date">');
					_html.push(iwk_date.formatFullDate(new Date(Number(_post.post_date)*1000)));
					_html.push('</div>');
					if(_post.meeting_id && _type != "meeting_list"){
						_html.push('<div class="btns_wrap meeting_btns_wrap">\
										<div class="meeting_img"></div>\
										<div class="fl">');
						_html.push('进入会议');
						_html.push('</div>\
										<div class="klearboth"></div>\
									</div>');
					}else{
						_html.push('<div class="btns_wrap reply_btns_wrap">\
										<div class="reply_img"></div>\
										<div class="fl">');
						_html.push(_post.comments_num);
						_html.push('条回复');
						_html.push('</div>\
										<div class="klearboth"></div>\
									</div>');
					}
					_html.push('<div class="klearboth"></div>\
							</div>\
						</div>');
					_html.push('<div class="post_footer hide">\
							<div class="footer_arrow"></div>\
							<input type="text" class="footer_input">\
							<div class="footer_send_btn" parent="0" data="public_');
					_html.push(_post.id);
					if(_type == "community_pop"){
						_html.push('" onclick="iwk_community_pop.comment_send(this,\''+_type+'\');">发&nbsp;送</div>');
					}else{
						_html.push('" onclick="iwk_community_pop.comment_send(this);">发&nbsp;送</div>');
					}
					_html.push('<div class="klearboth"></div>');
					_html.push('<a class="comment_attach" id="comment_attach_');
					_html.push(_post.id);
					_html.push('"></a>');
					_html.push('<div class="community_comment_attach_queue" id="comment_attach_queue_'+_post.id+'"></div>');
					_html.push('<div class="klearboth"></div>');
					_html.push('<ul class="reply_list">');
					_html.push(iwk_community_pop.init_comment_html(_post.comments,post_company_id));
					_html.push('</ul>\
							<div class="toggle_replay_wrap">\
								<div class="toggle_detail">收起</div>\
								<div class="up_arrow"></div>\
								<div class="klearboth"></div>\
							</div>\
						</div>\
					</div>');
					_html.push('<div class="klearboth"></div></div>');
					break;
				case 'EXP_MEETING':
					_html.push('<div class="post_line notice_pop" post_id="');
					_html.push(_post.id);
					_html.push('" cid="');
					_html.push(post_company_id);
					_html.push('" id="public_');
					_html.push(_post.id);
					_html.push('" meeting_id = "');
					_html.push(_post.id);
					_html.push('">');
					_html.push('<div class="post_body">\
							<div class="post_content_wrap">\
							<div class="post_content">');
					if(_post.meeting_cover){
						_html.push('<div class="content_cover_wrap">\
										<img alt="封面" class="content_cover" src="');
						_html.push(_post.meeting_cover);
						_html.push('">\
									</div>');
					}else{
						_html.push('<div class="content_cover_wrap exp_img meeting_img"></div>');
					}
					_html.push('<div class="content_text_wrap content_narrow">\
									<div class="content_title" title='+_post.title+'>');
					_html.push(_post.title);
					_html.push('</div>\
									<div class="content_text">');
					_html.push(_post.content);
					_html.push('</div>');
					_html.push('<div class="content_meeting_header"></div>');
					_html.push('</div>');
					if(_post.has_attachment){
						_html.push('<div class="attachs"><div class="attach_images klear" style="width:100%;">');
						for(var j = 0;j< _post.attachment['image'].length;j++){
							_image =  _post.attachment['image'][j];
							_pre = 0;
							_next = 0;
							if(j>0){
								_pre = 1;
							}
							if(j+1<_post.attachment['image'].length){
								_next = 1;
							}
							_html.push('<a href="javascript:;" data="'+''+'inside/getattachment/id:'+_image.attachment_id+'/cid:'+post_company_id+'" class="attach_image first" onclick="iwk_post.view_img_attach(this,'+_pre+','+_next+');">\
									<img src="'+''+'inside/get_file/id:'+_image.attachment_id+'/cid:'+post_company_id+'">\
									</a>');
						}
						_html.push('</div>');
						
						for(var j = 0;j < _post.attachment['file'].length;j++){
							_file =  _post.attachment['file'][j];
							_html.push('<div class="attach_file '+_file.file_type+'" onclick="iwk_post.view_file_attach(this);" data="'+''+'inside/getattachment/id:'+_file.attachment_id+'">');
							_html.push('<a href="javascript:;" title="'+_file.title+'" >'+_file.title+'</a>');
							_html.push('</div>');
						}
						
						for(var j = 0;j < _post.attachment['sound'].length;j++){
							_sound =  _post.attachment['sound'][j];
							_html.push('<a href="javascript:;" onclick="iwk_priv.play_audio('+''+'inside/getfile/aid:'+_sound.attachment_id+', this, event)" class="attach_sound_play"></a>');
						}
						_html.push('</div>');
					}
					_html.push('<div class="klearboth"></div>\
							</div>');
					_html.push('<div class="post_content_footer">\
								<div class="post_date">');
					_html.push(iwk_date.formatFullDate(new Date(Number(_post.post_date)*1000)));
					_html.push('</div>');
					_html.push('<div class="btns_wrap meeting_btns_wrap">\
									<div class="meeting_img"></div>\
									<div class="fl">');
					_html.push('进入会议');
					_html.push('</div>\
									<div class="klearboth"></div>\
								</div>');
					_html.push('<div class="klearboth"></div>\
							</div>\
						</div>');
					_html.push('</div>');
					_html.push('<div class="klearboth"></div></div>');
					break;
				case 'EXP_VOTE':
					_html.push('<div class="post_line vote_pop" post_id="');
					_html.push(_post.id);
					_html.push('" cid="');
					_html.push(post_company_id);
					_html.push('" id="public_');
					_html.push(_post.id);
					_html.push('">');
					_html.push('<div class="post_body">');
					_html.push('<div class="post_content_wrap">');
					_html.push('<div class="post_content">');
					_html.push('\
							<div class="content_cover_wrap exp_img vote_img">\
							</div>\
							<div class="content_text_wrap content_narrow">\
								<div class="content_title">请大家投票</div>\
								<div class="content_text">');
					_html.push(_post.content);
					_html.push('</div>\
							</div>');
					if(_post.has_attachment){
						_html.push('<div class="attachs"><div class="attach_images klear" style="width:100%;">');
						for(var j = 0;j< _post.attachment['image'].length;j++){
							_image =  _post.attachment['image'][j];
							_pre = 0;
							_next = 0;
							if(j>0){
								_pre = 1;
							}
							if(j+1<_post.attachment['image'].length){
								_next = 1;
							}
							_html.push('<a href="javascript:;" data="'+''+'inside/getattachment/id:'+_image.attachment_id+'/cid:'+post_company_id+'" class="attach_image first" onclick="iwk_post.view_img_attach(this,'+_pre+','+_next+');">\
									<img src="'+''+'inside/get_file/id:'+_image.attachment_id+'/cid:'+post_company_id+'">\
									</a>');
						}
						_html.push('</div>');
						
						for(var j = 0;j < _post.attachment['file'].length;j++){
							_file =  _post.attachment['file'][j];
							_html.push('<div class="attach_file '+_file.file_type+'" onclick="iwk_post.view_file_attach(this);" data="'+''+'inside/getattachment/id:'+_file.attachment_id+'">');
							_html.push('<a href="javascript:;" title="'+_file.title+'" >'+_file.title+'</a>');
							_html.push('</div>');
						}
						
						for(var j = 0;j < _post.attachment['sound'].length;j++){
							_sound =  _post.attachment['sound'][j];
							_html.push('<a href="javascript:;" onclick="iwk_priv.play_audio('+''+'inside/getfile/aid:'+_sound.attachment_id+', this, event)" class="attach_sound_play"></a>');
						}
						_html.push('</div>');
					}
					_html.push('<div class="klearboth"></div>\
						</div>');
					_html.push('<div class="toggle_detail_wrap">\
							<div class="toggle_detail">展开</div>\
							<div class="arrow_btn down_arrow"></div>\
							<div class="klearboth"></div>\
						</div>');
					_html.push('<div class="vote_detail hide">');
					
					if(_post.is_join){
						_html.push('<div class="isvw_wrap">\
							<div class="isvw_ttl">');
						_html.push(_post.content);
						_html.push('</div>\
							<div class="isvw_options">');
						
						var _sum = 0;
						var options_counts = {};
						for(var n = 0;n < _post.option_ids.length;n++){
							var _option = _post.vote_result[_post.option_ids[n]];
							var option_count = 0;
							for(var j in _option){
								option_count++;
							}
							options_counts[_post.option_ids[n]] = option_count;
							_sum += option_count;
						}
						for(var n = 0;n < _post.options.length;n++){
							var _count = options_counts[_post.options[n].id];
							_html.push('<div class="isvw_option">\
								<div class="widget_radio disabled">\
									<span class="checked"></span>\
								</div><span class="margin_r">'+iwk_community.abc[n]+'</span>');
							_html.push( _post.options[n].content);
							_html.push('</div>');
							_html.push('<div class="isvw_rate_block">\
								<div class="isvw_rate_wrap">\
									<div class="isvw_rate" style="width:');
							_html.push(parseInt(_count/_sum*100));
							_html.push('%;"></div>\
								</div>\
								<span class="isvw_rate_val">');
							_html.push(_count+" ("+parseInt(_count/_sum*100)+"%)");
							_html.push('</span>\
								<div class="klear"></div>\
							</div>');
						}
						_html.push("</div></div>");
					}else{
						var _cls = "";
						if(_post.vote_type == 1){
							_cls = "detail_line single";
						}else{
							_cls = "detail_line multi";
						}
						for(var j = 0;j < _post.options.length;j++){
							var _option = _post.options[j];
							_html.push('<div class="'+_cls+'" option_id="');
							_html.push(_option.id);
							_html.push('">\
									<div class="vote_sel_btn"></div>\
									<div class="detail_cont">');
							_html.push(_option.content);
							_html.push('</div>\
									<div class="klearboth"></div></div>');
						}
						_html.push('<div class="vote_btn_wrap">');
						_html.push('<div class="exp_end_time">'+iwk_date.formatFullDate(new Date(Number(_post.end_date)*1000))+'到期</div></div>');
						_html.push('<div class="vote_btn_wrap"><div class="commit_res vote_btn">提交投票</div></div>');
					}
					
					_html.push('</div>');
					_html.push('<div class="post_content_footer">\
							<div class="post_date">');
					_html.push(iwk_date.formatFullDate(new Date(Number(_post.post_date)*1000)));
					_html.push('</div>');
					_html.push('<div class="btns_wrap reply_btns_wrap">\
								<div class="reply_img"></div>\
								<div class="fl">');
					_html.push(_post.comments_num);
					_html.push('条回复</div>\
								<div class="klearboth"></div>\
							</div>');
					_html.push('<div class="klearboth"></div>\
						</div>');
					_html.push('</div>');
					_html.push('<div class="post_footer hide">\
							<div class="footer_arrow"></div>\
							<input type="text" class="footer_input">\
							<div class="footer_send_btn" parent="0" data="public_');
					_html.push(_post.id);
					_html.push('" onclick="iwk_community_pop.comment_send(this);">发&nbsp;送</div>\
							<div class="klearboth"></div>');
					_html.push('<a class="comment_attach" id="comment_attach_');
					_html.push(_post.id);
					_html.push('"></a>');
					_html.push('<div class="community_comment_attach_queue" id="comment_attach_queue_'+_post.id+'"></div>');
					_html.push('<div class="klearboth"></div>');
					_html.push('<ul class="reply_list">');
					_html.push(iwk_community_pop.init_comment_html(_post.comments,post_company_id));
					_html.push('</ul>\
							<div class="toggle_replay_wrap">\
								<div class="toggle_detail">收起</div>\
								<div class="up_arrow"></div>\
								<div class="klearboth"></div>\
							</div>\
						</div>');
					_html.push('</div><div class="klearboth"></div></div>');
					break;
				case 'EXP_SURVEY':
					_html.push('<div class="post_line survey_pop" post_id="');
					_html.push(_post.id);
					_html.push('" cid="');
					_html.push(post_company_id);
					_html.push('" id="public_');
					_html.push(_post.id);
					_html.push('">');
					_html.push('<div class="post_body">');
					_html.push('<div class="post_content_wrap">');
					_html.push('<div class="post_content">');
					_html.push('\
							<div class="content_cover_wrap exp_img survey_img">\
							</div>\
							<div class="content_text_wrap content_narrow">\
								<div class="content_title">调查问卷</div>\
								<div class="content_text">');
					_html.push(_post.content);
					_html.push('</div>\
							</div>');
					if(_post.has_attachment){
						_html.push('<div class="attachs"><div class="attach_images klear" style="width:100%;">');
						for(var j = 0;j< _post.attachment['image'].length;j++){
							_image =  _post.attachment['image'][j];
							_pre = 0;
							_next = 0;
							if(j>0){
								_pre = 1;
							}
							if(j+1<_post.attachment['image'].length){
								_next = 1;
							}
							_html.push('<a href="javascript:;" data="'+''+'inside/getattachment/id:'+_image.attachment_id+'/cid:'+post_company_id+'" class="attach_image first" onclick="iwk_post.view_img_attach(this,'+_pre+','+_next+');">\
									<img src="'+''+'inside/get_file/id:'+_image.attachment_id+'/cid:'+post_company_id+'">\
									</a>');
						}
						_html.push('</div>');
						
						for(var j = 0;j < _post.attachment['file'].length;j++){
							_file =  _post.attachment['file'][j];
							_html.push('<div class="attach_file '+_file.file_type+'" onclick="iwk_post.view_file_attach(this);" data="'+''+'inside/getattachment/id:'+_file.attachment_id+'">');
							_html.push('<a href="javascript:;" title="'+_file.title+'" >'+_file.title+'</a>');
							_html.push('</div>');
						}
						
						for(var j = 0;j < _post.attachment['sound'].length;j++){
							_sound =  _post.attachment['sound'][j];
							_html.push('<a href="javascript:;" onclick="iwk_priv.play_audio('+''+'inside/getfile/aid:'+_sound.attachment_id+', this, event)" class="attach_sound_play"></a>');
						}
						_html.push('</div>');
					}
					_html.push('<div class="klearboth"></div>\
						</div>');
					_html.push('<div class="toggle_detail_wrap">\
							<div class="toggle_detail">展开</div>\
							<div class="arrow_btn down_arrow"></div>\
							<div class="klearboth"></div>\
						</div>');
					_html.push('<div class="vote_detail hide">');
					
					if(_post.is_join){
						var question_index = 0;
						for(var n in _post.survey_result ){
							var _question = _post.survey_result[n];
							var _options = _post.questions[question_index];
							_html.push('<div class="isvw_wrap">\
								<div class="isvw_ttl">');
							_html.push("问题"+(question_index+1)+"："+_options.content);
							_html.push('</div>');
							if(_options.type == '2'){
								_html.push('<div class="isvw_options subjective">');
								for(var x in _question){
									for(var y in _question[x]){
										if(y == _post.accept_id){
											_html.push(_question[x][y].content);
										}
									}
								}
							}else{
								_html.push('<div class="isvw_options">');
								var _sum = 0;
								var options_counts = {};
								for(var n in _options.options){
									var _option = _question[n];
									var option_count = 0;
									for(var j in _option){
										option_count++;
									}
									options_counts[n] = option_count;
									_sum += option_count;
								}
								var _index = 0;
								for(var n in _options.options){
									var _count = options_counts[n];
									_html.push('<div class="isvw_option">\
										<div class="widget_radio disabled">\
											<span class="checked"></span>\
										</div><span class="margin_r">'+iwk_community.abc[_index++]+'</span>');
									var option_cont =  _options.options[n].content;
									if(option_cont == ""){
										for(var x in _question){
											for(var y in _question[x]){
												if(y == _post.accept_id){
													option_cont = '其他('+_question[x][y].content+")";
												}
											}
										}
									}
									_html.push( option_cont == ""?'其他':option_cont);
									_html.push('</div>');
									_html.push('<div class="isvw_rate_block">\
										<div class="isvw_rate_wrap">\
											<div class="isvw_rate" style="width:');
									_html.push(parseInt(_count/_sum*100));
									_html.push('%;"></div>\
										</div>\
										<span class="isvw_rate_val">');
									_html.push(_count+" ("+parseInt(_count/_sum*100)+"%)");
									_html.push('</span>\
										<div class="klear"></div>\
									</div>');
								}
							}
							_html.push("</div></div>");
							question_index++;
						}
						
					}else{
						for(var j = 0;j < _post.questions.length;j++){
							var _question = _post.questions[j];
							_html.push('<div class="survey_question_line" question_id="');
							_html.push(_question.id);
							_html.push('">');
							_html.push('<div class="survey_question">');
							_html.push('问题'+(j+1)+'：'+_question.content);
							_html.push('</div>');
							if(_question.type == 2){
								for(var idx in _question.options){
									_id = _question.options[idx].id;
								}
								_html.push('<div class="other_text_wrap" option_id=');
								_html.push(_id);
								_html.push('><div class="widget_ipt_lite_wrap" style="width:300px;margin-left:10px;">\
										<input type="text" class="widget_ipt_lite" style="width:300px;" value=""></div></div>');
							}else{
								var _line_cls = '';
								if(_question.option_type == '1'){
									_line_cls = "detail_line single";
								}else{
									_line_cls = "detail_line multi";
								}
								for(var idx in _question.options){
									var _option = _question.options[idx];
									var _cont_cls = "";
									var _cont = "";
									if(_option.is_subjective == 1){
										_cont_cls = " other";
										_cont = "其他";
									}else{
										_cont = _option.content;
									}
									_html.push('<div class="'+_line_cls+_cont_cls+'" option_id="');
									_html.push(_option.id);
									_html.push('">\
											<div class="vote_sel_btn"></div>\
											<div class="detail_cont">');
									_html.push(_cont);
									_html.push('</div>\
											<div class="klearboth"></div></div>');
								}
							}
							_html.push('</div>');
						}
						_html.push('<div class="vote_btn_wrap">');
						_html.push('<div class="exp_end_time">'+iwk_date.formatFullDate(new Date(Number(_post.end_date)*1000))+'到期</div></div>');
						_html.push('<div class="vote_btn_wrap"><div class="commit_res survey_btn">提交问卷</div></div>');
					}
					
					_html.push('</div>');
					_html.push('<div class="post_content_footer">\
							<div class="post_date">');
					_html.push(iwk_date.formatFullDate(new Date(Number(_post.post_date)*1000)));
					_html.push('</div>\
							<div class="btns_wrap reply_btns_wrap">\
								<div class="reply_img"></div>\
								<div class="fl">');
					_html.push(_post.comments_num);
					_html.push('条回复</div>\
								<div class="klearboth"></div>\
							</div>\
							<div class="klearboth"></div>\
						</div>');	
					_html.push('</div>');
					_html.push('<div class="post_footer hide">\
							<div class="footer_arrow"></div>\
							<input type="text" class="footer_input">\
							<div class="footer_send_btn" parent="0" data="public_');
					_html.push(_post.id);
					_html.push('" onclick="iwk_community_pop.comment_send(this);">发&nbsp;送</div>\
							<div class="klearboth"></div>');
					_html.push('<a class="comment_attach" id="comment_attach_');
					_html.push(_post.id);
					_html.push('"></a>');
					_html.push('<div class="community_comment_attach_queue" id="comment_attach_queue_'+_post.id+'"></div>');
					_html.push('<div class="klearboth"></div>');
					_html.push('<ul class="reply_list">');
					_html.push(iwk_community_pop.init_comment_html(_post.comments,post_company_id,_type));
					_html.push('</ul>\
							<div class="toggle_replay_wrap">\
								<div class="toggle_detail">收起</div>\
								<div class="up_arrow"></div>\
								<div class="klearboth"></div>\
							</div>\
						</div>');
					_html.push('</div>');
					_html.push('<div class="klearboth"></div>');
					_html.push('</div>');
					break;
				}
			}
			_html.push('</div>');
			$wrap.html($wrap.html()+_html.join(""));
			$(".community_pop_body .post_line .content_text_wrap img").hide();
			if($("#community_pop_body .post_line").length < list_count){
				$(".iwk_more_loader").show();
			}else{
				$(".iwk_more_loader").hide();
			}
		},
		init_comment_html : function(_comments,_id,_type){
			var _html = [];
			for(var n = 0;n < _comments.length;n++){
				var _comment = _comments[n];
				_html.push('<li comment_id="');
				_html.push(_comment.comment_id);
				_html.push('">\
						<img class="reply_photo" alt="" src="');
				_html.push(_comment.user_photo);
				_html.push('">');
				_html.push('<div class="reply_content">');
				_html.push('<div class="reply_user">');
				_html.push(_comment.name);
				_html.push('</div>');
				_html.push(_comment.comment_message);
				_html.push('<div class="reply_time">');
				_html.push(iwk_date.formatFullDate(new Date(Number(_comment.date)*1000)));
				_html.push('</div>');
				_html.push('</div>\
						<div class="reply" c_name="');
				_html.push(_comment.name);
				_html.push('" parent="');
				_html.push(_comment.comment_id);
				_html.push('">回复</div>\
						<div class="klearboth"></div>');
				if(_comment.attachment){
					_html.push('<div class="attachs"><div class="attach_images klear" style="width:100%;">');
					for(var j = 0;j< _comment.attachment['image'].length;j++){
						_image =  _comment.attachment['image'][j];
						_pre = 0;
						_next = 0;
						if(j>0){
							_pre = 1;
						}
						if(j+1<_comment.attachment['image'].length){
							_next = 1;
						}
						_html.push('<a href="javascript:;" data="'+''+'inside/getattachment/id:'+_image.attachment_id+"/cid:"+_id+'" class="attach_image first" onclick="iwk_post.view_img_attach(this,'+_pre+','+_next+');">\
								<img src="'+''+'inside/get_file/id:'+_image.attachment_id+"/cid:"+_id+'">\
								</a>');
					}
					_html.push('</div>');
					
					for(var j = 0;j < _comment.attachment['file'].length;j++){
						_file =  _comment.attachment['file'][j];
						_html.push('<div class="attach_file '+_file.file_type+'" onclick="iwk_post.view_file_attach(this);" data="'+''+'inside/getattachment/id:'+_file.attachment_id+'">');
						_html.push('<a href="javascript:;" title="'+_file.title+'" >'+_file.title+'</a>');
						_html.push('</div>');
					}
					_html.push('</div>');
				}
				if(_comment.recomments){
					for(var i = 0;i < _comment.recomments.length;i++){
						var _recomment = _comment.recomments[i];
						_html.push('<div class="recomment">');
						_html.push('<img class="reply_photo" src="');
						_html.push(_recomment.user_photo);
						_html.push('">');
						_html.push('<div class="reply_content">');
						_html.push('<div class="reply_user">');
						_html.push(_recomment.name);
						_html.push('</div>');
						_html.push(_recomment.comment_message);
						_html.push('<div class="reply_time">');
						_html.push(iwk_date.formatFullDate(new Date(Number(_comment.date)*1000)));
						_html.push('</div>');
						_html.push('</div>');
						_html.push('<div class="klearboth"></div>');
						
						if(_recomment.attachment){
							_html.push('<div class="attachs"><div class="attach_images klear" style="width:100%;">');
							for(var j = 0;j< _recomment.attachment['image'].length;j++){
								_image =  _recomment.attachment['image'][j];
								_pre = 0;
								_next = 0;
								if(j>0){
									_pre = 1;
								}
								if(j+1<_recomment.attachment['image'].length){
									_next = 1;
								}
								_html.push('<a href="javascript:;" data="'+''+'inside/getattachment/id:'+_image.attachment_id+"/cid:"+_id+'" class="attach_image first" onclick="iwk_post.view_img_attach(this,'+_pre+','+_next+');">\
										<img src="'+''+'inside/get_file/id:'+_image.attachment_id+"/cid:"+_id+'">\
										</a>');
							}
							_html.push('</div>');
							
							for(var j = 0;j < _recomment.attachment['file'].length;j++){
								_file =  _recomment.attachment['file'][j];
								_html.push('<div class="attach_file '+_file.file_type+'" onclick="iwk_post.view_file_attach(this);" data="'+''+'inside/getattachment/id:'+_file.attachment_id+'">');
								_html.push('<a href="javascript:;" title="'+_file.title+'" >'+_file.title+'</a>');
								_html.push('</div>');
							}
							_html.push('</div>');
						}
						
						_html.push('</div>');
					}
					_html.push('<div class="klearboth"></div>');
				}
				
				_html.push('</li>');
			}
			return _html.join("");
		},
		show_sign : function(e){
			$("#sign_in").css({'right':($(window).width()-980)/2}).show();
			$('body').bind("click",iwk_community_pop.hide_sign);
			iwk_common.stop_propagation(e);
		},
		hide_sign:function(){
			$("#sign_in").hide();
			$('body').unbind("click",iwk_community_pop.hide_sign);
		},
		comment_send:function(_this,_type){ 
			var _pid = $(_this).attr("data");
			var _li = $(_this).closest(".post_line");
			var _parent_data = $(_this).attr("parent");
			var _textarea = $(_this).prev();
			var _msg = $.trim(_textarea.val());
			var $ul = $(_this).closest(".post_footer").find("ul.reply_list");
			var _id = _li.attr("cid");
			var upload_list = $(_this).closest(".post_footer").find(".community_comment_attach_queue");
			if($(_this).attr("parent") != 0){
				_msg = _msg.replace(/^回复\s[^：.*]*：/,"");
			}
			var _parent = $(_this).closest("div.post_footer");
			var _data = {
				parent : _parent_data,
				postid : _pid,
				message : _msg,
				post_temp_id : iwk_cfg_comment.temp_id
			};

			if (_msg === "") {
				zebra_alert(iwk_lng.post_empty_comment);
				return;
			}
			if (iwk_cfg_comment.attach_sending) {
				zebra_alert(iwk_lng.attach_is_sending_msg);
				return;
			}
			if (iwk_cfg_comment.sending) {
				zebra_alert(iwk_lng.is_sending_msg);
				return;
			}

			_textarea.attr("disabled", "disabled");
			$(_this).attr("disabled", "disabled");

			iwk_cfg_comment.sending = 1;
			var _guid = $("#guid_hid").val();
			var _url = '';
			if(_type == "community_pop"){
				_url = '' + 'ajax/comment_community_ins';
			}else{
				_url = '' + 'ajax/postcomment_community/cid:'+_id+'/guid:'+_guid+'/r:' + Math.round(Math.random() * 1000);
			}
			$.post(_url, _data, function(res) {
				if (res.status.toLowerCase() == "ok") {
					_html = [];
					if(res.parent == 0){
						var _comment = JSON.parse(res.comment_cont);
						_html.push('<li comment_id="');
						_html.push(_comment.comment_id);
						_html.push('">\
								<img class="reply_photo" alt="" src="');
						_html.push(_comment.user_photo);
						_html.push('">');
						_html.push('<div class="reply_content">');
						_html.push('<div class="reply_user">');
						_html.push(_comment.name);
						_html.push('</div>');
						_html.push(_comment.comment_message);
						_html.push('<div class="reply_time">');
						_html.push(iwk_date.formatFullDate(new Date(Number(_comment.date)*1000)));
						_html.push('</div>');
						_html.push('</div>\
								<div class="reply" c_name="');
						_html.push(_comment.name);
						_html.push('" parent="');
						_html.push(_comment.comment_id);
						_html.push('">回复</div>\
								<div class="klearboth"></div>');
						if(_comment.attachment){
							_html.push('<div class="attachs"><div class="attach_images klear" style="width:100%;">');
							for(var j = 0;j< _comment.attachment['image'].length;j++){
								_image =  _comment.attachment['image'][j];
								_pre = 0;
								_next = 0;
								if(j>0){
									_pre = 1;
								}
								if(j+1<_comment.attachment['image'].length){
									_next = 1;
								}
								_html.push('<a href="javascript:;" data="'+''+'inside/getattachment/id:'+_image.attachment_id+"/cid:"+_id+'" class="attach_image first" onclick="iwk_post.view_img_attach(this,'+_pre+','+_next+');">\
										<img src="'+''+'inside/get_file/id:'+_image.attachment_id+"/cid:"+_id+'">\
										</a>');
							}
							_html.push('</div>');
							
							for(var j = 0;j < _comment.attachment['file'].length;j++){
								_file =  _comment.attachment['file'][j];
								_html.push('<div class="attach_file '+_file.file_type+'" onclick="iwk_post.view_file_attach(this);" data="'+''+'inside/getattachment/id:'+_file.attachment_id+'">');
								_html.push('<a href="javascript:;" title="'+_file.title+'" >'+_file.title+'</a>');
								_html.push('</div>');
							}
							_html.push('</div>');
						}
							_html.push('</li>');
							$ul.append(_html.join(""));
							var _reply = _li.find(".reply_btns_wrap .fl");
							_reply.html(Number(_reply.html().replace("条回复",""))+1+"条回复");
					}else{
						var _recomment = JSON.parse(res.comment_cont);
						_html.push('<div class="recomment">');
						_html.push('<img class="reply_photo" src="');
						_html.push(_recomment.user_photo);
						_html.push('">');
						_html.push('<div class="reply_content">');
						_html.push('<div class="reply_user">');
						_html.push(_recomment.name);
						_html.push('</div>');
						_html.push(_recomment.comment_message);
						_html.push('<div class="reply_time">');
						_html.push(iwk_date.formatFullDate(new Date(Number(_recomment.date)*1000)));
						_html.push('</div>');
						_html.push('</div>');
						_html.push('<div class="klearboth"></div>');
						
						if(_recomment.attachment){
							_html.push('<div class="attachs"><div class="attach_images klear" style="width:100%;">');
							for(var j = 0;j< _recomment.attachment['image'].length;j++){
								_image =  _recomment.attachment['image'][j];
								_pre = 0;
								_next = 0;
								if(j>0){
									_pre = 1;
								}
								if(j+1<_recomment.attachment['image'].length){
									_next = 1;
								}
								_html.push('<a href="javascript:;" data="'+''+'inside/getattachment/id:'+_image.attachment_id+"/cid:"+_id+'" class="attach_image first" onclick="iwk_post.view_img_attach(this,'+_pre+','+_next+');">\
										<img src="'+''+'inside/get_file/id:'+_image.attachment_id+"/cid:"+_id+'">\
										</a>');
							}
							_html.push('</div>');
							
							for(var j = 0;j < _recomment.attachment['file'].length;j++){
								_file =  _recomment.attachment['file'][j];
								_html.push('<div class="attach_file '+_file.file_type+'" onclick="iwk_post.view_file_attach(this);" data="'+''+'inside/getattachment/id:'+_file.attachment_id+'">');
								_html.push('<a href="javascript:;" title="'+_file.title+'" >'+_file.title+'</a>');
								_html.push('</div>');
							}
							_html.push('</div>');
						}
						_html.push('</div>');
						_html.push('<div class="klearboth"></div>');
						$ul.find("li[comment_id='"+_recomment.parent+"']").append(_html.join(""));
					}
					iwk_cfg_comment.sending = 0;
					_textarea.val("").removeAttr("disabled");
					$(_this).attr("parent",0);
					iwk_post.init_comment_cfg();
					upload_list.empty();
				} else {
					zebra_alert(res.message);
					iwk_cfg_comment.sending = 0;
					_textarea.removeAttr("disabled");
				}
			}, 'json');
		},
		comment_success:function(){
			iwk_cfg_comment.sending = 0;
			
		},
		input_data_remove : function(_input,e){
			var _btn = _input.next();
			if(_btn.attr("parent") == 0){
				return;
			}
			if(e.keyCode == 8 && _input.val().search(/^回复\s[^：.*]*$/) != -1){
				_input.val("");
				_btn.attr("parent",0);
			}
		},
		comment_reply : function(){
			$this = $(this);
			var _input = $this.closest("div.post_footer").find(">.footer_input");
			var _btn = $this.closest("div.post_footer").find(".footer_send_btn");
			_input.val("回复 "+$this.attr("c_name")+"：").focus();
			if(!_input.is(".keyupClass")){
				_input.addClass("keyupClass").bind("keyup",function(){
					iwk_community_pop.input_data_remove(_input,event);
				});
			}
			_btn.attr("parent",$this.attr("parent"));
		},
		signin : function(){
			var _guid = $("#guid_hid").val();
			var post_id = $("#community_pop_body>div.post_line").attr("post_id");
			$("#sign_form").attr("action",''+"exp/signin/guid:"+_guid+"/post_id:"+post_id).submit();
		},
		select_single_detail:function(){
			$(this).addClass("selected").siblings().removeClass("selected");
			$(this).siblings(".other").next().remove();
		},
		select_multi_detail:function(){
			$(this).toggleClass("selected");
		},
		select_other_detail:function(){
			var $this = $(this);
			if($this.is(".selected")){
				if($this.next().length != 0){
					return;
				}
				$this.after('<div class="other_text_wrap"><div class="widget_ipt_lite_wrap" style="width:300px;margin-left:10px;">\
						<input type="text" class="widget_ipt_lite" style="width:300px;" value="">\
						</div></div>').next().find("input").focus()
			}else{
				$this.next().remove();
			}
		},
		survey_submit : function(){
			$parent = $(this).closest('div.vote_detail');
			var _post_id = $parent.closest(".post_line").attr("post_id");
			var _answers = [];
			var $questions = $parent.find(".survey_question_line");
			for(var i = 0;i < $questions.length;i++){
				var $question = $($questions[i]);
				var _answer = {};
				_answer.question_id = $question.attr("question_id");
				_answer.answers = [];
				var $options = $question.find("div.detail_line.selected");
				if($options.length == 0 && $question.find(">.other_text_wrap input").val() != ""){//如果是主观题
					var _option = {};
					_option.option_id = $question.find(">.other_text_wrap").attr("option_id");
					_option.content = $question.find(">.other_text_wrap input").val();
					_answer.answers.push(_option);
				}else if($options.length == 0){
					zebra_alert("下面对应的题每个至少要选择一项或不能为空");
					return;
				}
				for(var j = 0;j < $options.length;j++){
					var $option = $($options[j]);
					var _option = {};
					_option.option_id = $option.attr("option_id");
					if($option.is(".other")){
						var _val = $option.next().find(".widget_ipt_lite").val();
						if(_val == ""){
							zebra_alert("下面对应的题每个至少要选择一项或不能为空");
							return;
						}
						_option.content = _val;
					}else{
						_option.content = $option.find(".detail_cont").html();
					}
					_answer.answers.push(_option);
				}
				_answers.push(_answer);
			}
			var _data = {'answers':JSON.stringify(_answers),'from':'survey_submit','post_id':_post_id};
			var _guid = $("#guid_hid").val();
			$.post( '' + "ajax/exp_submit/guid:"+_guid+"/r:" + Math.round(Math.random() * 1000),_data, function(res) {
				if(res == "ok"){
					zebra_alert("投票成功");
					window.location.reload();
				}else{
					zebra_alert(res);
				}
			},'text');
		},
		vote_submit : function(){
			$parent = $(this).closest('div.vote_detail');
			var _post_id = $parent.closest(".post_line").attr("post_id");
			var $options = $parent.find(".detail_line.selected");
			if($options.length == 0){
				zebra_alert("请至少选择一项吧！");
				return;
			}
			var _answers = [];
			for(var i = 0;i < $options.length;i++){
				_answers.push($($options[i]).attr("option_id"));
			}
			
			var _data = {'answers':JSON.stringify(_answers),'from':'vote_submit','post_id':_post_id};
			var _guid = $("#guid_hid").val();
			$.post( '' + "ajax/exp_submit/guid:"+_guid+"/r:" + Math.round(Math.random() * 1000),_data, function(res) {
				if(res == "ok"){
					zebra_alert("投票成功");
					window.location.reload();
				}else{
					zebra_alert(res);
				}
			},'text');
		},
		morer_wrap : function(_this,_from){
			if($(_this).find("a").find(".spinner").is(":visible")){
				return;
			}
			$(_this).find("a").find(".spinner").show();
			var _len = $(".community_pop_body>div").length;
			if(_from == "community_pop"){
				$.post(''+"inside/community/from:ajax/start_from:"+_len,function(res){
					iwk_community_pop.init_posts(res,_from);
					$(_this).find("a").find(".spinner").hide();
				},'json');
				return;
			}
			var _guid = $("#guid_hid").val();
			var _cid = window.location.href.match(/cid:\d*/)[0].replace('cid:',"");
			$.post(''+"exp/index/from:ajax/cid:"+_cid+"/start_from:"+_len+"/guid:"+_guid,function(res){
				iwk_community_pop.init_posts(res);
				$(_this).find("a").find(".spinner").hide();
			},'json');
		},
		signout : function(){
			window.location.href = ''+'exp/signout/guid:'+$("#guid_hid").val();
		},
		checkbox_clickf : function(obj){
			if($(obj).hasClass("disabled")){return;}

		},
		web_meeting : function(){
			var $this = $(this);
			var $li = $this.closest(".post_line");
			var _data = {};
			_data.post_id = $li.attr("post_id");
			var _guid = $("#guid_hid").val();
			var _url = '';
			var _cid = $li.attr("cid");
			var meeting_id = $li.attr("meeting_id");
			_url = '' + "exp/wap_meeting"+"/cid:"+_cid+"/meeting_id:"+meeting_id+"/post_id:"+_data.post_id+"/guid:"+_guid;
			window.location.href = _url;
		},
		cont_back : function(_cid){
			var _url = ''+"exp/cid:"+_cid+"/guid:"+$("#guid_hid").val();
			window.location.href = _url;
		},
		contactor_login : function(){
			
		}
};



//*图像缩放BEGIN*/zzz
var iwk_zoom_picpath= "inside/get_file/id:" ;
//var iwk_zoom_picpath="/iworker2/inside/get_file/id:" ;

(function(a, e, d) {
	e.fn.artZoom = function(w) {
		w = e.extend( {}, e.fn.artZoom.defaults, w );
		var q, v, i, m = this,
			h = {},
			r = w.path,
			j = r + "/loading.gif",
			t = r + "/zoomin.cur",
			s = r + "/zoomout.cur",
			n = w._onZoomInit || e.noop,
			o = w._onZoomIn || e.noop,
			l = w._onZoomOut || e.noop;
		new Image().src = j;
		t = "url('" + t + "'), pointer";
		s = "url('" + s + "'), pointer";
		q = ['<div class="ui-artZoom-toolbar">', '<span class="ui-artZoom-buttons">',
		     '<a href="javascript:" data-go="hide" class="ui-artZoom-hide"><span></span>', w.hide, "</a>", 
		     '<a href="javascript:" data-go="left" class="ui-artZoom-left"><span></span>', w.left, "</a>", 
		     '<a href="javascript:" data-go="right" class="ui-artZoom-right"><span></span>', w.right, "</a>", 
		     '<a href="javascript:" data-go="source" class="ui-artZoom-source"><span></span>', w.source, "</a>", "</span>", 
		     '<span class="ui-artZoom-loading"><br><center>', '<img data-live="stop" src="', j, '" style="', 
		     "display:inline-block;*zoom:1;*display:inline;vertical-align:middle;", 'width:16px;height:16px;"', " />", 
		     " <span>Loading..</span>", "</center></span>", "</div>", '<div class="ui-artZoom-box" style="display:none;cursor:', s, '">',
		     '<span class="ui-artZoom-photo" data-go="hide"', ' style="display:inline-block;*display:inline;*zoom:1;overflow:hidden;position:relative;*position:static;">', '<center><img data-name="thumb" data-go="hide" data-live="stop" src="', j, '" /></center>', "</span>", "</div>"].join("");
		var u = (function() {
			var C = {
				singleThumbWidth: 110,
				singlePageWidth: 440,
				defaultMaskLeft: 21,
				maxWidth: 415
			};

			function B(J, G, H) {
				var I = H && e(a).scrollTop();
				b(J, function() {
					var L = this.width,
						M = this.height,
						N = C.maxWidth;
					if (N >= L) {
						G.width(L);
						G.height(M)
					} else {
						if (N < L) {
							G.width(N);
							G.height(N / L * M)
						}
					}
				}, function() {
					if (G[0]["{$canvas}"]) {
						G[0]["{$canvas}"].style.display = "none";
						G.show()
					}
					G.attr("src", J);
					if (H) {
						e(a).scrollTop(I)
					}
				})
			}
			function F(M, H) {
				var I = [],	L;
				I.push('<div class="shutterCon" data-index="' + H + '" data-total="' + M.length + '"><span class="shutter-trans-mask"></span><a class="shutter-prev"><e><</e></a><ul class="shutter-thumb-con">');
				for (var J = 0, G = M.length; J < G; J++) {
					L = M[J];///zzzz
					I.push('<a data-index="' + L.index + '" data-id="' + L.id + '"><img src="' + L.src + '/type:0" /></a>')
					//alert (L.src)
				}
				I.push('</ul><a class="shutter-next"><e>></e></a></div>');
				return I.join("")
			}
			function D(M, J, O, I) {
				var H, P = I.closest(".shutterCon"),
					L = M % 4 ? Math.floor(M / 4 + 1) : M / 4,
					R = J % 4 ? Math.floor(J / 4 + 1) : J / 4,
					G = C.singleThumbWidth,
					N = C.singlePageWidth,
					Q = C.defaultMaskLeft;
				(function() {
					if (O <= 4) {
						P.data({
							startIndex: 1,
							endIndex: O,
							maskIndex: J
						});
						if (O == 1) {
							P.hide()
						}
						return
					} else {
						if (R * 4 <= O) {
							I.animate({
								marginLeft: "-" + N * (R - L)
							});
							P.data({
								startIndex: (R - 1) * 4 + 1,
								endIndex: R * 4,
								maskIndex: (J % 4 == 0) ? 4 : J % 4
							})
						}
						if (R * 4 > O) {
							H = N * (R - L) - (R * 4 - O) * G;
							I.animate({
								marginLeft: "-" + H
							});
							P.data({
								startIndex: O - 3,
								endIndex: O,
								maskIndex: 4 - (O - J)
							})
						}
					}
				})();
				if (R * 4 > O) {
					if (R == 1) {
						P.find(".shutter-trans-mask").animate({
							left: Q + (J - 1) * G
						})
					} else {
						P.find(".shutter-trans-mask").animate({
							left: Q + (3 - (O - J)) * G
						})
					}
				} else {
					P.find(".shutter-trans-mask").animate({
						left: Q + ((J % 4 == 0 ? 4 : J % 4) - 1) * G
					})
				}
			}
			function E(O) {
				var I = e(O.target).closest("a"),
					U = I.closest(".shutterCon"),
					M = U.data(),
					Q = M.all,
					P = M.index,
					V = M.maskIndex,
					H = U.prev().find("img.ui-artZoom-show"),
					W = H.offset().left,
					T = H.offset().top,
					S = U.find(".shutter-thumb-con"),
					R = U.find(".shutter-trans-mask"),
					L = I.hasClass("shutter-next");
				if (!L) {
					if (M.startIndex == 1) {
						if (V == 1) {
							/* show more other post pic zzz*/
						} else {
							R.animate({
								left: "-=" + C.singleThumbWidth
							});
							B(iwk_zoom_picpath + Q[P - 2].id + "/type:2", H, true);
							U.data("index", P - 1);
							U.data("maskIndex", V - 1)
						}
					} else {
						S.animate({
							marginLeft: "+=" + C.singleThumbWidth
						});
						B(iwk_zoom_picpath + Q[P - 2].id+ "/type:2", H, true);
						U.data("startIndex", M.startIndex - 1);
						U.data("endIndex", M.endIndex - 1);
						U.data("index", P - 1)
					}
				} else {
					if (M.endIndex == M.total) {
						if (V == 4 || V == M.total) {
							/* show more other post pic zzz*/
						} else {
							R.animate({
								left: "+=" + C.singleThumbWidth
							});
							B(iwk_zoom_picpath + Q[P].id+ "/type:2", H, true);
							U.data("index", P + 1);
							U.data("maskIndex", V + 1)
						}
					} else {
						S.animate({
							marginLeft: "-=" + C.singleThumbWidth
						});
						B(iwk_zoom_picpath + Q[P].id+ "/type:2", H, true);
						U.data("startIndex", M.startIndex + 1);
						U.data("endIndex", M.endIndex + 1);
						U.data("index", P + 1)
					}
				}
			}
			function z(N) {
				var I = e(N.target).closest("a"),
					Q = I.closest(".shutter-thumb-con"),
					R = Q.closest(".shutterCon"),
					J = R.data(),
					O = J.all,
					S = J.maskIndex,
					L = J.index,
					G = R.prev().find("img.ui-artZoom-show"),
					P = R.find(".shutter-trans-mask"),
					M = I.data("index"),
					T = M > L ? true : false;
				if (T) {
					P.animate({
						left: "+=" + (M - L) * C.singleThumbWidth
					})
				} else {
					P.animate({
						left: "-=" + (L - M) * C.singleThumbWidth
					})
				}
				var H = T ? (S + M - L) : (S - (L - M));
				R.data("index", M);
				R.data("maskIndex", H);
				B(iwk_zoom_picpath + O[M - 1].id+ "/type:2", G, true)
			}
			var y;

			function A(I) {
				var G = this,
					H = a.createElement("div");
				H.id = "shutter-more-container";
				H.className = "shutter-more-container";
				H.innerHTML = 'show more other post pic ';
				//a.body.appendChild(H);
				//zzz
				G.dom = H;
				e(".shutter-dialog-close").live("click", function() {
					G.hide()
				})
			}
			A.prototype = {
				constructor: A,
				show: function(H, G) {
					this.dom.style.display = "block";
					this.dom.style.left = H + "px";
					this.dom.style.top = G + "px"
				},
				hide: function() {
					this.dom.style.display = "none"
				},
				fillData: function(L, J) {
					var M = this.dom.lastChild,
						I = new K.SimpleTemplate();
					for (var H = 0, G = L.length; H < G; H++) {
						///zzzz
						I._('<a href="/getfile/' + J + '/profile" target="_blank"><img width="100" height="100" src="/getfile/' + L[H] + '" /></a>')
					}
					M.innerHTML = I.toString()
				}
			};
			return {
				init: D,
				createTpl: F,
				switchThumb: E,
				selectThumb: z,
				calcImgCursor: f,
				imgResize: B,
				getMoreImgDialogInstance: function() {
					if (!y) {
						y = new A()
					}
					return y
				},
				execute: function(G) {
					return this[G] && this[G].apply(this, Array.prototype.slice.call(arguments, 1))
				}
			}
		})();
		var k, g, p;

		function f(I, y) {
			var C = e(I.currentTarget),
				G = I.pageX - C.offset().left,
				J = C.find(".ui-artZoom-photo"),
				B = (k = k || C.width()),
				H = (g = g || B / 3),
				L = (p = p || B / 3 * 2),
				F = y.data(),
				z = F.index,
				D = z == 1,
				E = z == F.total,
				A = e("#shutter-more-container").is(":visible");
			if (G < H && !D) {
				J.data("go", "prev");
				C[0].style.cursor = "url(" + '' + "/themes/art/imgs/pic_prev.cur),pointer"
			} else {
				if (G > L && (!E || !A)) {
					J.data("go", "next");
					C[0].style.cursor = "url(" + '' + "/themes/art/imgs/pic_next.cur),pointer"
				} else {
					J.data("go", "hide");
					C[0].style.cursor = s
				}
			}
		}
		e("body").on("click", ".shutter-prev,.shutter-next", function(y) {
			u.switchThumb(y)
		}).on("click", ".shutter-thumb-con a", function(y) {
			u.selectThumb(y)
		}).on("mousemove", ".ui-artZoom-box", function(A) {
			var y = e(this).next(".shutterCon");
			var z = y.data("total") || 0;
			if (z <= 1 || x) {
				return
			}
			x = setTimeout(function() {
				u.calcImgCursor(A, y);
				clearTimeout(x);
				x = null
			})
		});
		var x;
		this.live("click", function(Q) {
			if (this.nodeName !== "IMG" && this.getAttribute("data-live") === "stop") {
				return false
			}
			i = e(Q.target);
			var y, P, F = this,
				D = e(F),
				J = D.parent(),
				A = J.data("index") || 1,
				E = F.src,
				W = D.attr("data-artZoom-show") || E,
				N = D.attr("data-artZoom-source") || W,
				U = w.maxWidth || (J[0].nodeName === "A" ? D.parent() : D).parent().width(),
				M = w.maxHeight || 99999;
			U = U - w.borderWidth;
			if (J[0].nodeName === "A") {
				W = J.attr("data-artZoom-show") || J.attr("href");
				N = J.attr("data-artZoom-source") || J.attr("rel")
			}
			n.call(D);
			if (!D.closest(".msg-attach-pics").find(".shutterCon").length) {
				var I = a.createElement("div"),
					G, T, z;
				y = e(I);
				I.className = "ui-artZoom zoom-box ui-artZoom-noLoad";
				var H = e(this).closest(".msg-attach-pics").find("a.zoom-min"),
					S = H.length,
					V, B = [];
				for (var R = 0; R < S; R++) {
					V = H[R];
					B.push({
						index: R + 1,
						src: V.href,
						id: V.getAttribute("attachid")
						//id: V.href.slice(V.href.lastIndexOf("/id:") + 1)  //图片id
					})
				}
				I.innerHTML = q + u.execute("createTpl", B, A);
				e(I).find(".shutterCon").data("all", B);
				(J[0].nodeName === "A" ? D.parent() : D).before(I);
				D.data("artZoom", y);
				T = y.find(".ui-artZoom-box");
				G = y.find("[data-name=thumb]");
				J.closest(".msg-attach-pics").find("a.zoom-min,p.doc-show-ctrl").hide();
				var L = J.closest(".msg-attach-pics").find(".shutter-thumb-con");
				u.execute("init", 1, A, B.length, L);
				b(W, function() {
					var ab = this.width,
						aa = this.height,
						Z = Math.min(U, ab);
					aa = Z / ab * aa;
					ab = Z;
					G.attr("src", E).css(w.blur ? {
						width: ab + "px",
						height: aa + "px"
					} : {
						display: "none"
					}).after(['<img class="ui-artZoom-show" title="', F.title, '" alt="', F.alt, '" src="', W, '" style="width:', ab, "px;height:", aa, 'px;position:absolute;left:0;top:0;background:transparent;"', " />"].join(""));
					z = y.find(".ui-artZoom-show");
					G.attr("class", "ui-artZoom-show");
					y.addClass("ui-artZoom-ready");
					D.data("artZoom-ready", true);
					T.show()
				}, function() {
					G.removeAttr("class").hide();
					z.css({
						position: "static",
						left: "auto",
						top: "auto"
					});
					y.removeClass("ui-artZoom-noLoad");
					y.find(".ui-artZoom-loading").hide();
					D.data("artZoom-load", true)
				}, function() {
					y.addClass("ui-artZoom-error");
					d('jQuery.fn.artZoom: Load "' + W + '" Error!')
				})
			} else {
				var L = J.closest(".msg-attach-pics").find(".shutter-thumb-con"),
					O = L.closest(".shutterCon"),
					X = O.find(".shutter-trans-mask"),
					Y = O.data("total");
				J.closest(".msg-attach-pics").find("a.zoom-min,p.doc-show-ctrl").hide();
				L.css("marginLeft", 0);
				X.css("left", 21);
				O.closest(".ui-artZoom").show();
				u.execute("init", 1, A, Y, L);
				O.data("index", J.data("index"));
				u.execute("imgResize", iwk_zoom_picpath + O.find('a[data-index="' + O.data("index") + '"]').data("id") +"/type:2", O.prev(".ui-artZoom-box").find("img.ui-artZoom-show"))
			}
			y = D.closest(".msg-attach-pics").find(".ui-artZoom");
			O = y.find(".shutterCon");
			var C = y.find("[data-go]");
			P = function(ae) {
				var ag = ae.target,
					Z = e(ag),
					ad = Z.data("go") || Z.find(".ui-artZoom-photo").data("go") || Z.closest(".ui-artZoom-photo").data("go"),
					ac = ag.getAttribute("data-live"),
					af = D.data("artZoom-degree") || 0,
					ab = y.find(".ui-artZoom-show")[0];
				if (ac === "stop") {
					return false
				}
				var aa = e("#shutter-more-container");
				switch (ad) {
				case "left":
					af -= 90;
					af = af === -90 ? 270 : af;
					break;
				case "right":
					af += 90;
					af = af === 360 ? 0 : af;
					break;
				case "source":
					window.open(iwk_zoom_picpath + O.find('a[data-index="' + O.data("index") + '"]').data("id") + "/type:1");
					break;
				case "hide":
					o.call(i);
					J.closest(".msg-attach-pics").find("a.zoom-min,p.doc-show-ctrl").show();
					if (J.closest(".msg-attach-pics").find("a.zoom-min").length > 4) {
						J.closest(".msg-attach-pics").find("p.doc-show-ctrl").addClass("doc-show-ctrl-up")
					}
					y.hide();
					e(this).unbind("click", P);
					if (aa[0] && aa.is(":visible")) {
						aa[0].style.display = "none"
					}
					break;
				case "next":
					O.find(".shutter-next").trigger("click");
					f(ae, O);
					break;
				case "prev":
					O.find(".shutter-prev").trigger("click");
					f(ae, O);
					if (aa[0] && aa.is(":visible")) {
						aa[0].style.display = "none"
					}
					break
				}
				if ((ad === "left" || ad === "right")) {
					c(ab, af, U, M);
					D.data("artZoom-degree", af)
				}
				return
			};
			y.show().find(".ui-artZoom-toolbar").show();
			C.parents("div.ui-artZoom").bind("click", P);
			 
			l.call(y);
			return false
		});
		this.live("mouseover", function() {
			if (this.className !== "ui-artZoom-show") {
				this.style.cursor = t
			}
		});
		if (this[0]) {
			this[0].style.cursor = t
		}
		return this
	};
	e.fn.artZoom.defaults = {
		path: "./image",
		left: "左旋转",
		right: "右旋转",
		source: "看原图",
		hide: "×",
		blur: true,
		preload: true,
		maxWidth: null,
		maxHeight: null,
		borderWidth: 18
	};
	var c = e.imgRotate = function() {
			var g = "{$canvas}",
				f = !! a.createElement("canvas").getContext;
			return function(l, n, t, u) {
				var q, p, s, k = 1,
					i = l.naturalWidth,
					v = l.naturalHeight,
					j = l[g];
				if (!l[g]) {
					if (!("naturalWidth" in l)) {
						var m = l.runtimeStyle,
							r = m.width,
							o = m.height;
						m.width = m.height = "auto";
						l.naturalWidth = i = l.width;
						l.naturalHeight = v = l.height;
						m.width = r;
						m.height = o
					}
					l[g] = j = a.createElement(f ? "canvas" : "span");
					l.parentNode.insertBefore(j, l.nextSibling);
					l.style.display = "none";
					j.className = l.className;
					j.title = l.title;
					if (!f) {
						j.img = a.createElement("img");
						j.img.src = l.src;
						j.appendChild(j.img);
						j.style.cssText = "display:inline-block;*zoom:1;*display:inline;padding:0;margin:0;border:none 0;position:static;float:none;overflow:hidden;width:auto;height:auto"
					}
				}
				l.style.display = "none";
				j.style.display = "inline-block";
				var z = function(h) {
						if (h) {
							i = [v, v = i][0]
						}
						if (i > t) {
							k = t / i;
							v = k * v;
							i = t
						}
						if (v > u) {
							k = k * u / v;
							i = u / v * i;
							v = u
						}
						if (f) {
							(h ? v : i) / l.naturalWidth
						}
					};
				switch (n) {
				case 0:
					q = 0;
					p = 0;
					z();
					break;
				case 90:
					q = 0;
					p = -l.naturalHeight;
					z(true);
					break;
				case 180:
					q = -l.naturalWidth;
					p = -l.naturalHeight;
					z();
					break;
				case 270:
					q = -l.naturalWidth;
					p = 0;
					z(true);
					break
				}
				if (f) {
					j.setAttribute("width", i);
					j.setAttribute("height", v);
					s = j.getContext("2d");
					s.rotate(n * Math.PI / 180);
					s.scale(k, k);
					s.drawImage(l, q, p)
				} else {
					j.style.width = i + "px";
					j.style.height = v + "px";
					j.img.style.filter = "progid:DXImageTransform.Microsoft.BasicImage(rotation=" + n / 90 + ")";
					j.img.width = l.width * k;
					j.img.height = l.height * k
				}
			}
		}();
	var b = (function() {
		var i = [],
			h = null,
			g = function() {
				var j = 0;
				for (; j < i.length; j++) {
					i[j].end ? i.splice(j--, 1) : i[j]()
				}!i.length && f()
			},
			f = function() {
				clearInterval(h);
				h = null
			};
		return function(k, p, r, o) {
			var q, l, s, n, j, m = new Image();
			m.src = k;
			if (m.complete) {
				p.call(m);
				r && r.call(m);
				return
			}
			l = m.width;
			s = m.height;
			m.onerror = function() {
				o && o.call(m);
				q.end = true;
				m = m.onload = m.onerror = null
			};
			q = function() {
				n = m.width;
				j = m.height;
				if (n !== l || j !== s || n * j > 1024) {
					p.call(m);
					q.end = true
				}
			};
			q();
			m.onload = function() {
				!q.end && q();
				r && r.call(m);
				m = m.onload = m.onerror = null
			};
			if (!q.end) {
				i.push(q);
				if (h === null) {
					h = setInterval(g, 40)
				}
			}
		}
	})()
}(document, jQuery, function(a) {
	window.console && console.log(a)
}));


var iwk_zoom ={
	imageArtZoom: function() {
      var b = 100, a = 100;
      $(".zoom-min img").artZoom({
			path: '' + "themes/art/imgs",   //放大缩小图标路径
			preload: true,
			blur: true,
			hide: "收起",
			left: "向左转",
			right: "向右转",
			source: "查看原图",
			_onZoomInit: function() {
					this.closest("div.msg-attach-pics").find(".zoom-box:visible a.ui-artZoom-hide").click()
				},
				
			_onZoomOut: function() {
				if (this.length > 0) {
					var c = this.offset().top - a;
					if (c < $(window).scrollTop()) {
						$(window).scrollTop(c)
					}
				}
			},
			_onZoomIn: function() {
				var g = $(window), f = this.closest(".msg"), d = this.closest(".zoom-min").prev(".zoom-box:visible");
				if (f.length > 0 && d.length > 0) {
					var c = f.offset().top - a, e = d.offset().top - a;
					if (e < g.scrollTop()) {
						g.scrollTop(c)
					}
				}
			}
		});
      $(".zoom-min").live("click", function(c) {
          $(this).find("img").click();
          return false
      })
  }
};

//iwk_zoom.imageArtZoom();
$(document).ready
(
	function()
	{ 
		iwk_zoom.imageArtZoom();
	}
); 
//*图像缩放END*/zzz